diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 77de1a30b..f8947e84d 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-29T01:49:00","documenter_version":"1.1.2"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-29T17:47:37","documenter_version":"1.1.2"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 1daa3efd3..aa726544b 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -7,14 +7,14 @@ to calculate extra whitespace padding. - `whitespaces`. Number of whitespaces between the alignment character and the prior FST node. If this is > 1 it signifies additional whitespace was -manually added by the user since the formatter would only use 0 or 1 whitespaces.source
JuliaFormatter.DefaultStyleType
DefaultStyle

The default formatting style. See the Style section of the documentation for more details.

See also: BlueStyle, YASStyle, SciMLStyle, MinimalStyle

source
JuliaFormatter.FSTType

Formatted Syntax Tree

source
JuliaFormatter.MinimalStyleType
MinimalStyle()
source
JuliaFormatter.add_node!Method
add_node!(
+manually added by the user since the formatter would only use 0 or 1 whitespaces.
source
JuliaFormatter.DefaultStyleType
DefaultStyle

The default formatting style. See the Style section of the documentation for more details.

See also: BlueStyle, YASStyle, SciMLStyle, MinimalStyle

source
JuliaFormatter.FSTType

Formatted Syntax Tree

source
JuliaFormatter.MinimalStyleType
MinimalStyle()
source
JuliaFormatter.add_node!Method
add_node!(
     t::FST,
     n::FST,
     s::State;
     join_lines::Bool = false,
     max_padding::Int = -1,
     override_join_lines_based_on_source::Bool = false,
-)

Appends n to t.

  • join_lines if false a NEWLINE node will be added and n will appear

on the next line, otherwise it will appear on the same line as the previous node (when printing).

  • max_padding >= 0 indicates margin of t should be based on whether the margin

of n + max_padding is greater than the current margin of t. Otherwise the margin n will be added to t.

  • override_join_lines_based_on_source is only used when join_lines_based_on_source option is true. In which

n is added to t as if join_lines_based_on_source was false.

source
JuliaFormatter.align_binaryopcalls!Method
align_binaryopcalls!(fst::FST, op_inds::Vector{Int})

Aligns binary operator expressions.

Additionally handles the case where a keyword such as const is used prior to the binary op call.

source
JuliaFormatter.align_conditional!Method
align_conditional!(fst::FST)

Aligns a conditional expression.

source
JuliaFormatter.align_matrix!Method

Adjust whitespace in between matrix elements such that it's the same as the original source file.

source
JuliaFormatter.align_struct!Method
align_struct!(fst::FST)

Aligns struct fields.

source
JuliaFormatter.annotate_typefields_with_any!Method
annotate_typefields_with_any!(fst::FST, s::State)

Annotates fields in a type definitions with ::Any if no type annotation is provided.

source
JuliaFormatter.binaryop_to_whereop!Method
binaryop_to_whereop(fst::FST, s::State)

Handles the case of a function def defined as:

foo(a::A)::R where A = body

In this case instead of it being parsed as (1):

Binary
+)

Appends n to t.

  • join_lines if false a NEWLINE node will be added and n will appear

on the next line, otherwise it will appear on the same line as the previous node (when printing).

  • max_padding >= 0 indicates margin of t should be based on whether the margin

of n + max_padding is greater than the current margin of t. Otherwise the margin n will be added to t.

  • override_join_lines_based_on_source is only used when join_lines_based_on_source option is true. In which

n is added to t as if join_lines_based_on_source was false.

source
JuliaFormatter.align_binaryopcalls!Method
align_binaryopcalls!(fst::FST, op_inds::Vector{Int})

Aligns binary operator expressions.

Additionally handles the case where a keyword such as const is used prior to the binary op call.

source
JuliaFormatter.align_conditional!Method
align_conditional!(fst::FST)

Aligns a conditional expression.

source
JuliaFormatter.align_matrix!Method

Adjust whitespace in between matrix elements such that it's the same as the original source file.

source
JuliaFormatter.align_struct!Method
align_struct!(fst::FST)

Aligns struct fields.

source
JuliaFormatter.annotate_typefields_with_any!Method
annotate_typefields_with_any!(fst::FST, s::State)

Annotates fields in a type definitions with ::Any if no type annotation is provided.

source
JuliaFormatter.binaryop_to_whereop!Method
binaryop_to_whereop(fst::FST, s::State)

Handles the case of a function def defined as:

foo(a::A)::R where A = body

In this case instead of it being parsed as (1):

Binary
  - Where
  - OP
  - RHS

It's parsed as (2):

Binary
@@ -25,7 +25,7 @@
    - R
    - ...
  - OP
- - RHS

(1) is preferrable since it's the same parsed result as:

foo(a::A) where A = body

This transformation converts (2) to (1).

ref https://github.com/julia-vscode/CSTParser.jl/issues/93

source
JuliaFormatter.eq_to_in_normalization!Method
eq_to_in_normalization!(fst::FST, always_for_in::Bool, for_in_replacement::String)
+ - RHS

(1) is preferrable since it's the same parsed result as:

foo(a::A) where A = body

This transformation converts (2) to (1).

ref https://github.com/julia-vscode/CSTParser.jl/issues/93

source
JuliaFormatter.eq_to_in_normalization!Method
eq_to_in_normalization!(fst::FST, always_for_in::Bool, for_in_replacement::String)
 eq_to_in_normalization!(fst::FST, always_for_in::Nothing, for_in_replacement::String)

Transforms

for i = iter body end
 
 =>
@@ -34,16 +34,16 @@
 
 =>
 
-for i = 1:10 body end

always_for_in=nothing disables this normalization behavior.

  • https://github.com/domluna/JuliaFormatter.jl/issues/34
source
JuliaFormatter.flatten_binaryopcallMethod

Flattens a binary operation call tree if the operation repeats 2 or more times. "a && b && c" will be transformed while "a && b" will not.

source
JuliaFormatter.formatMethod
format(path, style::AbstractStyle; options...)::Bool
source
JuliaFormatter.formatMethod
format(
+for i = 1:10 body end

always_for_in=nothing disables this normalization behavior.

  • https://github.com/domluna/JuliaFormatter.jl/issues/34
source
JuliaFormatter.flatten_binaryopcallMethod

Flattens a binary operation call tree if the operation repeats 2 or more times. "a && b && c" will be transformed while "a && b" will not.

source
JuliaFormatter.formatMethod
format(path, style::AbstractStyle; options...)::Bool
source
JuliaFormatter.formatMethod
format(
     paths; # a path or collection of paths
     options...,
-)::Bool

Recursively descend into files and directories, formatting any .jl files.

See format_file and format_text for a description of the options.

This function will look for .JuliaFormatter.toml in the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found. When found, the configurations in the file will overwrite the given options. See Configuration File for more details.

Output

Returns a boolean indicating whether the file was already formatted (true) or not (false).

source
JuliaFormatter.formatMethod
format(mod::Module, args...; options...)
source
JuliaFormatter.format_fileMethod
format_file(
+)::Bool

Recursively descend into files and directories, formatting any .jl files.

See format_file and format_text for a description of the options.

This function will look for .JuliaFormatter.toml in the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found. When found, the configurations in the file will overwrite the given options. See Configuration File for more details.

Output

Returns a boolean indicating whether the file was already formatted (true) or not (false).

source
JuliaFormatter.formatMethod
format(mod::Module, args...; options...)
source
JuliaFormatter.format_fileMethod
format_file(
     filename::AbstractString;
     overwrite::Bool = true,
     verbose::Bool = false,
     format_markdown::Bool = false,
     format_options...,
-)::Bool

Formats the contents of filename assuming it's a .jl, .md, .jmd or .qmd file.

File Options

overwrite

default: true

If true the file will be reformatted in place, overwriting the existing file; if it is false, the formatted version of foo.jl will not be written anywhere.

verbose

default: false

If true details related to formatting the file will be printed to stdout.

format_markdown

default: false

If true, Markdown files are also formatted. Julia code blocks will be formatted in addition to the Markdown being normalized.

Formatting Options

See format_text for description of formatting options.

Output

Returns a boolean indicating whether the file was already formatted (true) or not (false).

source
JuliaFormatter.format_mdMethod
format_md(text::AbstractString; style::AbstractStyle = DefaultStyle(), kwargs...)

Normalizes the Markdown source and formats Julia code blocks.

See format_text for description of formatting options.

source
JuliaFormatter.format_textMethod
format_text(
+)::Bool

Formats the contents of filename assuming it's a .jl, .md, .jmd or .qmd file.

File Options

overwrite

default: true

If true the file will be reformatted in place, overwriting the existing file; if it is false, the formatted version of foo.jl will not be written anywhere.

verbose

default: false

If true details related to formatting the file will be printed to stdout.

format_markdown

default: false

If true, Markdown files are also formatted. Julia code blocks will be formatted in addition to the Markdown being normalized.

Formatting Options

See format_text for description of formatting options.

Output

Returns a boolean indicating whether the file was already formatted (true) or not (false).

source
JuliaFormatter.format_mdMethod
format_md(text::AbstractString; style::AbstractStyle = DefaultStyle(), kwargs...)

Normalizes the Markdown source and formats Julia code blocks.

See format_text for description of formatting options.

source
JuliaFormatter.format_textMethod
format_text(
     text::AbstractString;
     style::AbstractStyle = DefaultStyle(),
     indent::Int = 4,
@@ -184,7 +184,7 @@
 
 Can be used when `always_for_in` is `true` to replace the default `in` with `∈` (`\in`),
 or `=` instead. The replacement options are `("in", "=", "∈")`.
-

julia for a = 1:10 end

formatted with alwaysforin = true, forinreplacement = "∈"

for a ∈ 1:10 end ```

source
JuliaFormatter.has_semicolonMethod
has_semicolon(d::Document, line::Integer)

Returns whether d has a valid semicolon grouping on line.

source
JuliaFormatter.is_dot_opMethod
is_dot_op(x::CSTParser.EXPR)

Checks if the binary operation is a dot operation (e.g. x.y, x..z, x...z). This is different from a dot or broadcast operation.

source
JuliaFormatter.is_iterable_argMethod

Returns whether fst can be an iterable argument. For example in the case of a function call, which is of type Call:

(a, b, c; k1=v1)

This would return true for a, b, c and k1=v1 and false for all other nodes.

source
JuliaFormatter.is_standalone_shortcircuitMethod
is_standalone_shortcircuit(cst::CSTParser.EXPR)

Returns true if the cst is a short-circuit expression (uses &&, ||) and is standalone, meaning it's not directly associated with another statement or expression.

Examples

# this IS a standalone short-circuit
+

julia for a = 1:10 end

formatted with alwaysforin = true, forinreplacement = "∈"

for a ∈ 1:10 end ```

source
JuliaFormatter.has_semicolonMethod
has_semicolon(d::Document, line::Integer)

Returns whether d has a valid semicolon grouping on line.

source
JuliaFormatter.is_dot_opMethod
is_dot_op(x::CSTParser.EXPR)

Checks if the binary operation is a dot operation (e.g. x.y, x..z, x...z). This is different from a dot or broadcast operation.

source
JuliaFormatter.is_iterable_argMethod

Returns whether fst can be an iterable argument. For example in the case of a function call, which is of type Call:

(a, b, c; k1=v1)

This would return true for a, b, c and k1=v1 and false for all other nodes.

source
JuliaFormatter.is_standalone_shortcircuitMethod
is_standalone_shortcircuit(cst::CSTParser.EXPR)

Returns true if the cst is a short-circuit expression (uses &&, ||) and is standalone, meaning it's not directly associated with another statement or expression.

Examples

# this IS a standalone short-circuit
 a && b
 
 # this IS NOT a standalone short-circuit
@@ -199,21 +199,21 @@
 
 # operation inside parenthesis IS NOT a standalone short-circuit
 # operation outside parenthesis IS a standalone short-circuit
-(a && b) && c
source
JuliaFormatter.length_toMethod
`length_to(x::FST, ntyps; start::Int = 1)`

Returns the length to any node type in ntyps based off the start index.

source
JuliaFormatter.long_to_short_function_def!Method
long_to_short_function_def!(fst::FST, s::State)

Transforms a long function definition

function f(arg2, arg2)
+(a && b) && c
source
JuliaFormatter.length_toMethod
`length_to(x::FST, ntyps; start::Int = 1)`

Returns the length to any node type in ntyps based off the start index.

source
JuliaFormatter.long_to_short_function_def!Method
long_to_short_function_def!(fst::FST, s::State)

Transforms a long function definition

function f(arg2, arg2)
     body
-end

to a short function definition

f(arg1, arg2) = body
source
JuliaFormatter.move_at_sign_to_the_endMethod
move_at_sign_to_the_end(fst::FST, s::State)

NOTE: Assumes fst is the caller name of a macrocall such as @macro or Module.@macro.

Moves @ to the last identifier.

Example:

@Module.macro

to

Module.@macro
source
JuliaFormatter.nest_if_over_margin!Method
nest_if_over_margin!(
+end

to a short function definition

f(arg1, arg2) = body
source
JuliaFormatter.move_at_sign_to_the_endMethod
move_at_sign_to_the_end(fst::FST, s::State)

NOTE: Assumes fst is the caller name of a macrocall such as @macro or Module.@macro.

Moves @ to the last identifier.

Example:

@Module.macro

to

Module.@macro
source
JuliaFormatter.nest_if_over_margin!Method
nest_if_over_margin!(
     style,
     fst::FST,
     s::State,
     idx::Int;
     stop_idx::Union{Int,Nothing} = nothing,
-)::Bool

Converts the node at idx to a NEWLINE if the current margin plus the additional margin from fst[idx:stop_idx-1] is greater than the allowed margin.

If stop_idx == nothing the range is fst[idx:end].

Returns whether nesting occurred.

source
JuliaFormatter.p_macrostr_identifierMethod

This is a special prettifier to handle the case of string macros. As such it is not part of pretty.

format"hello"

The above "format" identifier is parsed by CSTParser as if the text is "@format_str". This creates problems when we format without intervention:

  1. "@format_str" is printed instead of "format"
  2. The state offset is incorrect since the length of "@format_str" is greater than "format"
source
JuliaFormatter.parent_isMethod

Returns whether the first unignored parent of cst matches the criteria determined by valid, which is a function that returns a boolean. ignore can be used to ignore certain parent nodes if desired, also a function which returns a boolean.

source
JuliaFormatter.pipe_to_function_call_pass!Method
pipe_to_function_call_pass!(fst::FST)

Rewrites x |> f to f(x).

source
JuliaFormatter.prepend_return!Method
prepend_return!(fst::FST, s::State)

Prepends return to the last expression of a block if applicable.

function foo()
+)::Bool

Converts the node at idx to a NEWLINE if the current margin plus the additional margin from fst[idx:stop_idx-1] is greater than the allowed margin.

If stop_idx == nothing the range is fst[idx:end].

Returns whether nesting occurred.

source
JuliaFormatter.p_macrostr_identifierMethod

This is a special prettifier to handle the case of string macros. As such it is not part of pretty.

format"hello"

The above "format" identifier is parsed by CSTParser as if the text is "@format_str". This creates problems when we format without intervention:

  1. "@format_str" is printed instead of "format"
  2. The state offset is incorrect since the length of "@format_str" is greater than "format"
source
JuliaFormatter.parent_isMethod

Returns whether the first unignored parent of cst matches the criteria determined by valid, which is a function that returns a boolean. ignore can be used to ignore certain parent nodes if desired, also a function which returns a boolean.

source
JuliaFormatter.pipe_to_function_call_pass!Method
pipe_to_function_call_pass!(fst::FST)

Rewrites x |> f to f(x).

source
JuliaFormatter.prepend_return!Method
prepend_return!(fst::FST, s::State)

Prepends return to the last expression of a block if applicable.

function foo()
     a = 2 * 3
     a / 3
 end

to

function foo()
     a = 2 * 3
     return a / 3
-end
source
JuliaFormatter.remove_superfluous_whitespace!Method
remove_superfluous_whitespace!(fst::FST)

Soft deletes WHITESPACE or PLACEHOLDER that's directly followed by a NEWLINE or INLINECOMMENT node.

source
JuliaFormatter.separate_kwargs_with_semicolon!Method
separate_kwargs_with_semicolon!(fst::FST)

Ensures keyword arguments are separated by a ";".

Examples

Replace "," with ";".

a = f(x, y = 3)
+end
source
JuliaFormatter.remove_superfluous_whitespace!Method
remove_superfluous_whitespace!(fst::FST)

Soft deletes WHITESPACE or PLACEHOLDER that's directly followed by a NEWLINE or INLINECOMMENT node.

source
JuliaFormatter.separate_kwargs_with_semicolon!Method
separate_kwargs_with_semicolon!(fst::FST)

Ensures keyword arguments are separated by a ";".

Examples

Replace "," with ";".

a = f(x, y = 3)
 
 ->
 
@@ -221,6 +221,6 @@
 
 ->
 
-a = f(; x = 1, y = 2)
source
JuliaFormatter.short_to_long_function_def!Method
short_to_long_function_def!(fst::FST, s::State)

Transforms a short function definition

f(arg1, arg2) = body

to a long function definition

function f(arg2, arg2)
+a = f(; x = 1, y = 2)
source
JuliaFormatter.short_to_long_function_def!Method
short_to_long_function_def!(fst::FST, s::State)

Transforms a short function definition

f(arg1, arg2) = body

to a long function definition

function f(arg2, arg2)
     body
-end
source
JuliaFormatter.unnestable_nodeMethod

cst is assumed to be a single child node. Returns true if the node is of the syntactic form {...}, [...], or (...).

source
JuliaFormatter.walkMethod
walk(f, fst::FST, s::State)

Walks fst calling f on each node.

In situations where descending further into a subtree is not desirable f should return a value other than nothing.

Note

This function mutates the State's (s) line_offset. If this is not desired you should save the value before calling this function and restore it after.

source
+endsource
JuliaFormatter.unnestable_nodeMethod

cst is assumed to be a single child node. Returns true if the node is of the syntactic form {...}, [...], or (...).

source
JuliaFormatter.walkMethod
walk(f, fst::FST, s::State)

Walks fst calling f on each node.

In situations where descending further into a subtree is not desirable f should return a value other than nothing.

Note

This function mutates the State's (s) line_offset. If this is not desired you should save the value before calling this function and restore it after.

source
diff --git a/dev/blue_style/index.html b/dev/blue_style/index.html index 63b5a632c..38cde2a6e 100644 --- a/dev/blue_style/index.html +++ b/dev/blue_style/index.html @@ -1,3 +1,3 @@ -Blue Style · JuliaFormatter

Blue Style

JuliaFormatter.BlueStyleType
BlueStyle()

Formatting style based on BlueStyle and JuliaFormatter#283.

Note

This style is still work-in-progress, and does not yet implement all of the BlueStyle guide.

Configurable options with different defaults to DefaultStyle are:

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

Configuration File Example

The .JuliaFormatter.toml which represents these settings is

style = "blue"

Or to use BlueStyle except change one of the settings:

style = "blue"
-remove_extra_newlines = false

Direct Usage

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

Or to use BlueStyle except change one of the settings:

format("file.jl", BlueStyle(), remove_extra_newlines=false)
+Blue Style · JuliaFormatter

Blue Style

JuliaFormatter.BlueStyleType
BlueStyle()

Formatting style based on BlueStyle and JuliaFormatter#283.

Note

This style is still work-in-progress, and does not yet implement all of the BlueStyle guide.

Configurable options with different defaults to DefaultStyle are:

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

Configuration File Example

The .JuliaFormatter.toml which represents these settings is

style = "blue"

Or to use BlueStyle except change one of the settings:

style = "blue"
+remove_extra_newlines = false

Direct Usage

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

Or to use BlueStyle except change one of the settings:

format("file.jl", BlueStyle(), remove_extra_newlines=false)
diff --git a/dev/config/index.html b/dev/config/index.html index 1120116b5..fa97b7cda 100644 --- a/dev/config/index.html +++ b/dev/config/index.html @@ -13,4 +13,4 @@ │ ├─ .JuliaFormatter.toml │ └─ sub_code1.jl └─ subdir2 - └─ sub_code2.jl

and call format("dir"), code.jl and sub_code2.jl will be formatted according to the rules defined in dir/.JuliaFormatter.toml, while formatting sub_code1.jl will be configured by dir/subdir1/.JuliaFormatter.toml.

Ignoring specific files and directories

If there is an entry in .JuliaFormatter.toml with

ignore = ["file.jl", "directory", "file_*.jl"]

then all of these files will be reported as already formatted: ./file.jl, ./directory/something.jl ./other_directory/file.jl, file_1.jl, .other_directory/file_name.jl.

+ └─ sub_code2.jl

and call format("dir"), code.jl and sub_code2.jl will be formatted according to the rules defined in dir/.JuliaFormatter.toml, while formatting sub_code1.jl will be configured by dir/subdir1/.JuliaFormatter.toml.

Ignoring specific files and directories

If there is an entry in .JuliaFormatter.toml with

ignore = ["file.jl", "directory", "file_*.jl"]

then all of these files will be reported as already formatted: ./file.jl, ./directory/something.jl ./other_directory/file.jl, file_1.jl, .other_directory/file_name.jl.

diff --git a/dev/custom_alignment/index.html b/dev/custom_alignment/index.html index fadc75f49..7137afd04 100644 --- a/dev/custom_alignment/index.html +++ b/dev/custom_alignment/index.html @@ -133,4 +133,4 @@ 100 300 400 1 ee 40000 2 a b -] +] diff --git a/dev/custom_styles/index.html b/dev/custom_styles/index.html index c7a8300f5..cad5eee83 100644 --- a/dev/custom_styles/index.html +++ b/dev/custom_styles/index.html @@ -32,4 +32,4 @@ foo(a, b, key1 = val1, key3 = val4) julia> format_text(s, style=CustomStyle()) |> print -foo(a, b, key1=val1, key3=val4)

Nice! Looks like it's working.

+foo(a, b, key1=val1, key3=val4)

Nice! Looks like it's working.

diff --git a/dev/how_it_works/index.html b/dev/how_it_works/index.html index 6cb6407c2..cd9d9f0c7 100644 --- a/dev/how_it_works/index.html +++ b/dev/how_it_works/index.html @@ -31,4 +31,4 @@ ..., argument120 ) # way over margin limit !!! -end

You can read how code is nested in the style section.

Once the FST has been nested it's then printed out to a file and voila! You have a formatted version of your code!

+end

You can read how code is nested in the style section.

Once the FST has been nested it's then printed out to a file and voila! You have a formatted version of your code!

diff --git a/dev/index.html b/dev/index.html index 72e5ac886..92a8f828d 100644 --- a/dev/index.html +++ b/dev/index.html @@ -180,4 +180,4 @@ a * b end -end

Notice the contents of @muladd begin is not indented.

#!: format: noindent can also be nested.

Editor Plugins

For integration with other editors:

+end

Notice the contents of @muladd begin is not indented.

#!: format: noindent can also be nested.

Editor Plugins

For integration with other editors:

diff --git a/dev/integrations/index.html b/dev/integrations/index.html index d349ac439..cc82d2544 100644 --- a/dev/integrations/index.html +++ b/dev/integrations/index.html @@ -5,4 +5,4 @@ rev: "v1.0.18" # or whatever the desired release is hooks: - id: "julia-formatter" -# ... other repos you may have

You can find a list of releases here. Be sure to use the entire version string! (You can double-check this by opening the release and looking at the part of the URL that follows .../releases/tag/VERSION.)

+# ... other repos you may have

You can find a list of releases here. Be sure to use the entire version string! (You can double-check this by opening the release and looking at the part of the URL that follows .../releases/tag/VERSION.)

diff --git a/dev/sciml_style/index.html b/dev/sciml_style/index.html index 0adaf3513..cc6ff1898 100644 --- a/dev/sciml_style/index.html +++ b/dev/sciml_style/index.html @@ -1,5 +1,5 @@ -SciML Style · JuliaFormatter

SciML Style

JuliaFormatter.SciMLStyleType
SciMLStyle()

Formatting style based on SciMLStyle.

Note

This style is still work-in-progress.

Configurable options with different defaults to DefaultStyle are:

  • whitespace_ops_in_indices = true
  • remove_extra_newlines = true
  • always_for_in = true
  • whitespace_typedefs = true,
  • normalize_line_endings = "unix"
source

Configuration File Example

The .JuliaFormatter.toml which represents these settings is

style = "sciml"

Or to use SciMLStyle except change one of the settings:

style = "sciml"
+SciML Style · JuliaFormatter

SciML Style

JuliaFormatter.SciMLStyleType
SciMLStyle()

Formatting style based on SciMLStyle.

Note

This style is still work-in-progress.

Configurable options with different defaults to DefaultStyle are:

  • whitespace_ops_in_indices = true
  • remove_extra_newlines = true
  • always_for_in = true
  • whitespace_typedefs = true,
  • normalize_line_endings = "unix"
source

Configuration File Example

The .JuliaFormatter.toml which represents these settings is

style = "sciml"

Or to use SciMLStyle except change one of the settings:

style = "sciml"
 remove_extra_newlines = false

Direct Usage

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

Or to use SciMLStyle except change one of the settings:

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

Additional Options

The SciMLStyle supports the additional options variable_call_indent and yas_style_nesting.

The option variable_call_indent is set to [] by default. It allows calls without aligning to the opening parenthesis:

# Allowed with and without `Dict in variable_call_indent`
 Dict{Int, Int}(1 => 2,
     3 => 4)
@@ -20,4 +20,4 @@
                            argument3, argument4,
                            argument5, x, y, z)
     foo(x) + goo(y)
-end
+end
diff --git a/dev/skipping_formatting/index.html b/dev/skipping_formatting/index.html index 65021b673..95a2ef53f 100644 --- a/dev/skipping_formatting/index.html +++ b/dev/skipping_formatting/index.html @@ -12,4 +12,4 @@ module Foo ... -end
Ignoring files

You can also ignore entire files and directories by supplying the ignore option in .JuliaFormatter.toml.

Note the formatter expects #! format: on and #! format: off to be on its own line and the whitespace to be an exact match.

+end
Ignoring files

You can also ignore entire files and directories by supplying the ignore option in .JuliaFormatter.toml.

Note the formatter expects #! format: on and #! format: off to be on its own line and the whitespace to be an exact match.

diff --git a/dev/style/index.html b/dev/style/index.html index b319561b5..cc640cccd 100644 --- a/dev/style/index.html +++ b/dev/style/index.html @@ -206,4 +206,4 @@ arg1, arg2, arg3, -) +) diff --git a/dev/transforms/index.html b/dev/transforms/index.html index c7303d13e..7ede437d3 100644 --- a/dev/transforms/index.html +++ b/dev/transforms/index.html @@ -42,4 +42,4 @@ -> -Module.@macro +Module.@macro diff --git a/dev/yas_style/index.html b/dev/yas_style/index.html index 250ccfc09..2ad723c98 100644 --- a/dev/yas_style/index.html +++ b/dev/yas_style/index.html @@ -1,5 +1,5 @@ -YAS Style · JuliaFormatter

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"
+YAS Style · JuliaFormatter

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) =
@@ -13,4 +13,4 @@
 # will be changed to the first example when `Dict ∉ variable_call_indent`.
 Dict{Int,Int}(
     1 => 2,
-    3 => 4)
+ 3 => 4)