YAS Style

JuliaFormatter.YASStyleType
YASStyle()

Formatting style based on YASGuide and JuliaFormatter#198.

Configurable options with different defaults to DefaultStyle are:

  • always_for_in = true
  • whitespace_ops_in_indices = true
  • remove_extra_newlines = true
  • import_to_using = true
  • pipe_to_function_call = true
  • short_to_long_function_def = true
  • always_use_return = true
  • whitespace_in_kwargs = false
  • join_lines_based_on_source = true
  • separate_kwargs_with_semicolon = true
source

Configuration File Example

The .JuliaFormatter.toml which represents these settings is

style = "yas"

Or to use YASStyle except change one of the settings:

style = "yas"
remove_extra_newlines = false

Direct Usage

format("file.jl", YASStyle())

Or to use YASStyle except change one of the settings:

format("file.jl", YASStyle(), remove_extra_newlines=false)

Differences from DefaultStyle

There are three main differences between YASStyle and DefaultStyle. They are based on alignment and line break behaviors.

  1. Arguments are aligned to just after the start of the opener [, {, (, etc.
function_call(arg1,
              arg2)
  1. As you can see from the above the closer sticks to the final argument.

  2. Nesting (line breaks) only occur when the margin of the next argument exceeds the maximim limit.

function_call(arg1, arg2,
              arg3)

arg3 exceeded the margin limit and so it was placed on the following line.

Nesting =

Unlike DefaultStyle, assignment operations = are not nested. That is, the following

my_function(arg1, arg2) = arg1 * arg2

Is not nested to

my_function(arg1, arg2) =
    arg1 * arg2

It is highly recommended setting short_to_long_function_def to true. This option transforms the above to a long function definition if it exceeds the maximum margin.

function my_function(arg1, arg2)
    arg1 * arg2
end