JuliaFormatter.DefaultStyle
— TypeDefaultStyle
The default formatting style. See the Style section of the documentation for more details.
See also: BlueStyle
, YASStyle
, SciMLStyle
, MinimalStyle
diff --git a/previews/PR818/.documenter-siteinfo.json b/previews/PR818/.documenter-siteinfo.json
index a51a01773..f07fbeed8 100644
--- a/previews/PR818/.documenter-siteinfo.json
+++ b/previews/PR818/.documenter-siteinfo.json
@@ -1 +1 @@
-{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-03-02T22:26:33","documenter_version":"1.3.0"}}
\ No newline at end of file
+{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-03-02T22:32:48","documenter_version":"1.3.0"}}
\ No newline at end of file
diff --git a/previews/PR818/api/index.html b/previews/PR818/api/index.html
index 7887fc664..af5a07051 100644
--- a/previews/PR818/api/index.html
+++ b/previews/PR818/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 The default formatting style. See the Style section of the documentation for more details. See also: Formatted Syntax Tree The default formatting style. See the Style section of the documentation for more details. See also: Formatted Syntax Tree Appends on the next line, otherwise it will appear on the same line as the previous node (when printing). of Aligns binary operator expressions. Additionally handles the case where a keyword such as Aligns a conditional expression. Adjust whitespace in between matrix elements such that it's the same as the original source file. Aligns struct fields. Annotates fields in a type definitions with Handles the case of a function def defined as: In this case instead of it being parsed as (1): Appends on the next line, otherwise it will appear on the same line as the previous node (when printing). of Aligns binary operator expressions. Additionally handles the case where a keyword such as Aligns a conditional expression. Adjust whitespace in between matrix elements such that it's the same as the original source file. Aligns struct fields. Annotates fields in a type definitions with Handles the case of a function def defined as: In this case instead of it being parsed as (1): It's parsed as (2): (1) is preferrable since it's the same parsed result as: This transformation converts (2) to (1). ref https://github.com/julia-vscode/CSTParser.jl/issues/93 (1) is preferrable since it's the same parsed result as: This transformation converts (2) to (1). ref https://github.com/julia-vscode/CSTParser.jl/issues/93 Transforms Finds the optimal placeholders to turn into a newlines such that the length of the arguments on each line is as close as possible while following margin constraints. 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. Finds the optimal placeholders to turn into a newlines such that the length of the arguments on each line is as close as possible while following margin constraints. 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. Recursively descend into files and directories, formatting any See This function will look for Output Returns a boolean indicating whether the file was already formatted ( Recursively descend into files and directories, formatting any See This function will look for Output Returns a boolean indicating whether the file was already formatted ( Formats the contents of See https://domluna.github.io/JuliaFormatter.jl/dev/#File-Options for details on available options. Output Returns a boolean indicating whether the file was already formatted ( Normalizes the Markdown source and formats Julia code blocks. See Formats the contents of See https://domluna.github.io/JuliaFormatter.jl/dev/#File-Options for details on available options. Output Returns a boolean indicating whether the file was already formatted ( Normalizes the Markdown source and formats Julia code blocks. See Formats a Julia source passed in as a string, returning the formatted code as another string. See https://domluna.github.io/JuliaFormatter.jl/dev/#Formatting-Options for details on available options. Returns whether Checks if the binary operation is a dot operation (e.g. Returns whether This would return Returns Examples Formats a Julia source passed in as a string, returning the formatted code as another string. See https://domluna.github.io/JuliaFormatter.jl/dev/#Formatting-Options for details on available options. Returns whether Checks if the binary operation is a dot operation (e.g. Returns whether This would return Returns Examples Returns the length to any node type in Transforms a long function definition Returns the length to any node type in Transforms a long function definition to a short function definition NOTE: Assumes Moves Example: to to a short function definition NOTE: Assumes Moves Example: to Converts the node at If Returns whether nesting occurred. This is a special prettifier to handle the case of string macros. As such it is not part of The above "format" identifier is parsed by CSTParser as if the text is "@format_str". This creates problems when we format without intervention: Returns whether the first unignored parent of Rewrites Prepends Converts the node at If Returns whether nesting occurred. This is a special prettifier to handle the case of string macros. As such it is not part of The above "format" identifier is parsed by CSTParser as if the text is "@format_str". This creates problems when we format without intervention: Returns whether the first unignored parent of Rewrites Prepends to Soft deletes Ensures keyword arguments are separated by a ";". Examples Replace "," with ";". Soft deletes Ensures keyword arguments are separated by a ";". Examples Replace "," with ";". Transforms a short function definition to a long function definition Transforms a short function definition to a long function definition Walks In situations where descending further into a subtree is not desirable This function mutates the State's (JuliaFormatter.DefaultStyle
— TypeDefaultStyle
BlueStyle
, YASStyle
, SciMLStyle
, MinimalStyle
JuliaFormatter.FST
— TypeJuliaFormatter.MinimalStyle
— TypeMinimalStyle()
JuliaFormatter.add_node!
— Methodadd_node!(
+manually added by the user since the formatter would only use 0 or 1 whitespaces.
JuliaFormatter.DefaultStyle
— TypeDefaultStyle
BlueStyle
, YASStyle
, SciMLStyle
, MinimalStyle
JuliaFormatter.FST
— TypeJuliaFormatter.MinimalStyle
— TypeMinimalStyle()
JuliaFormatter.add_node!
— Methodadd_node!(
t::FST,
n::FST,
s::State;
join_lines::Bool = false,
max_padding::Int = -1,
override_join_lines_based_on_source::Bool = false,
-)
n
to t
.join_lines
if false
a NEWLINE node will be added and n
will appearmax_padding
>= 0 indicates margin of t
should be based on whether the marginn
+ 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 whichn
is added to t
as if join_lines_based_on_source
was false.JuliaFormatter.align_binaryopcalls!
— Methodalign_binaryopcalls!(fst::FST, op_inds::Vector{Int})
const
is used prior to the binary op call.JuliaFormatter.align_conditional!
— Methodalign_conditional!(fst::FST)
JuliaFormatter.align_matrix!
— MethodJuliaFormatter.align_struct!
— Methodalign_struct!(fst::FST)
JuliaFormatter.annotate_typefields_with_any!
— Methodannotate_typefields_with_any!(fst::FST, s::State)
::Any
if no type annotation is provided.JuliaFormatter.binaryop_to_whereop!
— Methodbinaryop_to_whereop(fst::FST, s::State)
foo(a::A)::R where A = body
Binary
+)
n
to t
.join_lines
if false
a NEWLINE node will be added and n
will appearmax_padding
>= 0 indicates margin of t
should be based on whether the marginn
+ 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 whichn
is added to t
as if join_lines_based_on_source
was false.JuliaFormatter.align_binaryopcalls!
— Methodalign_binaryopcalls!(fst::FST, op_inds::Vector{Int})
const
is used prior to the binary op call.JuliaFormatter.align_conditional!
— Methodalign_conditional!(fst::FST)
JuliaFormatter.align_matrix!
— MethodJuliaFormatter.align_struct!
— Methodalign_struct!(fst::FST)
JuliaFormatter.annotate_typefields_with_any!
— Methodannotate_typefields_with_any!(fst::FST, s::State)
::Any
if no type annotation is provided.JuliaFormatter.binaryop_to_whereop!
— Methodbinaryop_to_whereop(fst::FST, s::State)
foo(a::A)::R where A = body
Binary
- Where
- OP
- RHS
Binary
@@ -25,7 +25,7 @@
- R
- ...
- OP
- - RHS
foo(a::A) where A = body
JuliaFormatter.eq_to_in_normalization!
— Methodeq_to_in_normalization!(fst::FST, always_for_in::Bool, for_in_replacement::String)
+ - RHS
foo(a::A) where A = body
JuliaFormatter.eq_to_in_normalization!
— Methodeq_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)
for i = iter body end
=>
@@ -34,16 +34,16 @@
=>
-for i = 1:10 body end
always_for_in=nothing
disables this normalization behavior.JuliaFormatter.find_optimal_nest_placeholders
— MethodJuliaFormatter.flatten_binaryopcall
— MethodJuliaFormatter.format
— Methodformat(path, style::AbstractStyle; options...)::Bool
JuliaFormatter.format
— Methodformat(
+for i = 1:10 body end
always_for_in=nothing
disables this normalization behavior.JuliaFormatter.find_optimal_nest_placeholders
— MethodJuliaFormatter.flatten_binaryopcall
— MethodJuliaFormatter.format
— Methodformat(path, style::AbstractStyle; options...)::Bool
JuliaFormatter.format
— Methodformat(
paths; # a path or collection of paths
options...,
-)::Bool
.jl
files.format_file
and format_text
for a description of the options..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.true
) or not (false
).JuliaFormatter.format
— Methodformat(mod::Module, args...; options...)
JuliaFormatter.format_file
— Methodformat_file(
+)::Bool
.jl
files.format_file
and format_text
for a description of the options..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.true
) or not (false
).JuliaFormatter.format
— Methodformat(mod::Module, args...; options...)
JuliaFormatter.format_file
— Methodformat_file(
filename::AbstractString;
overwrite::Bool = true,
verbose::Bool = false,
format_markdown::Bool = false,
format_options...,
-)::Bool
filename
assuming it's a .jl
, .md
, .jmd
or .qmd
file.true
) or not (false
).JuliaFormatter.format_md
— Methodformat_md(text::AbstractString; style::AbstractStyle = DefaultStyle(), kwargs...)
format_text
for description of formatting options.JuliaFormatter.format_text
— Methodformat_text(
+)::Bool
filename
assuming it's a .jl
, .md
, .jmd
or .qmd
file.true
) or not (false
).JuliaFormatter.format_md
— Methodformat_md(text::AbstractString; style::AbstractStyle = DefaultStyle(), kwargs...)
format_text
for description of formatting options.JuliaFormatter.format_text
— Methodformat_text(
text::AbstractString;
style::AbstractStyle = DefaultStyle(),
indent::Int = 4,
@@ -75,7 +75,7 @@
surround_whereop_typeparameters::Bool = true,
variable_call_indent::Vector{String} = []
short_circuit_to_if::Bool = false,
-)::String
JuliaFormatter.has_semicolon
— Methodhas_semicolon(d::Document, line::Integer)
d
has a valid semicolon grouping on line
.JuliaFormatter.is_dot_op
— Methodis_dot_op(x::CSTParser.EXPR)
x.y
, x..z
, x...z
). This is different from a dot or broadcast operation.JuliaFormatter.is_iterable_arg
— Methodfst
can be an iterable argument. For example in the case of a function call, which is of type Call
:(a, b, c; k1=v1)
true
for a
, b
, c
and k1=v1
and false
for all other nodes.JuliaFormatter.is_standalone_shortcircuit
— Methodis_standalone_shortcircuit(cst::CSTParser.EXPR)
true
if the cst
is a short-circuit expression (uses &&
, ||
) and is standalone, meaning it's not directly associated with another statement or expression.# this IS a standalone short-circuit
+)::String
JuliaFormatter.has_semicolon
— Methodhas_semicolon(d::Document, line::Integer)
d
has a valid semicolon grouping on line
.JuliaFormatter.is_dot_op
— Methodis_dot_op(x::CSTParser.EXPR)
x.y
, x..z
, x...z
). This is different from a dot or broadcast operation.JuliaFormatter.is_iterable_arg
— Methodfst
can be an iterable argument. For example in the case of a function call, which is of type Call
:(a, b, c; k1=v1)
true
for a
, b
, c
and k1=v1
and false
for all other nodes.JuliaFormatter.is_standalone_shortcircuit
— Methodis_standalone_shortcircuit(cst::CSTParser.EXPR)
true
if the cst
is a short-circuit expression (uses &&
, ||
) and is standalone, meaning it's not directly associated with another statement or expression.# this IS a standalone short-circuit
a && b
# this IS NOT a standalone short-circuit
@@ -90,21 +90,21 @@
# operation inside parenthesis IS NOT a standalone short-circuit
# operation outside parenthesis IS a standalone short-circuit
-(a && b) && c
JuliaFormatter.length_to
— Method`length_to(x::FST, ntyps; start::Int = 1)`
ntyps
based off the start
index.JuliaFormatter.long_to_short_function_def!
— Methodlong_to_short_function_def!(fst::FST, s::State)
function f(arg2, arg2)
+(a && b) && c
JuliaFormatter.length_to
— Method`length_to(x::FST, ntyps; start::Int = 1)`
ntyps
based off the start
index.JuliaFormatter.long_to_short_function_def!
— Methodlong_to_short_function_def!(fst::FST, s::State)
function f(arg2, arg2)
body
-end
f(arg1, arg2) = body
JuliaFormatter.move_at_sign_to_the_end
— Methodmove_at_sign_to_the_end(fst::FST, s::State)
fst
is the caller name of a macrocall such as @macro
or Module.@macro
.@
to the last identifier.@Module.macro
Module.@macro
JuliaFormatter.nest_if_over_margin!
— Methodnest_if_over_margin!(
+end
f(arg1, arg2) = body
JuliaFormatter.move_at_sign_to_the_end
— Methodmove_at_sign_to_the_end(fst::FST, s::State)
fst
is the caller name of a macrocall such as @macro
or Module.@macro
.@
to the last identifier.@Module.macro
Module.@macro
JuliaFormatter.nest_if_over_margin!
— Methodnest_if_over_margin!(
style,
fst::FST,
s::State,
idx::Int;
stop_idx::Union{Int,Nothing} = nothing,
-)::Bool
idx
to a NEWLINE
if the current margin plus the additional margin from fst[idx:stop_idx-1]
is greater than the allowed margin.stop_idx == nothing
the range is fst[idx:end]
.JuliaFormatter.p_macrostr_identifier
— Methodpretty
.format"hello"
JuliaFormatter.parent_is
— Methodcst
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.JuliaFormatter.pipe_to_function_call_pass!
— Methodpipe_to_function_call_pass!(fst::FST)
x |> f
to f(x)
.JuliaFormatter.prepend_return!
— Methodprepend_return!(fst::FST, s::State)
return
to the last expression of a block if applicable.function foo()
+)::Bool
idx
to a NEWLINE
if the current margin plus the additional margin from fst[idx:stop_idx-1]
is greater than the allowed margin.stop_idx == nothing
the range is fst[idx:end]
.JuliaFormatter.p_macrostr_identifier
— Methodpretty
.format"hello"
JuliaFormatter.parent_is
— Methodcst
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.JuliaFormatter.pipe_to_function_call_pass!
— Methodpipe_to_function_call_pass!(fst::FST)
x |> f
to f(x)
.JuliaFormatter.prepend_return!
— Methodprepend_return!(fst::FST, s::State)
return
to the last expression of a block if applicable.function foo()
a = 2 * 3
a / 3
end
function foo()
a = 2 * 3
return a / 3
-end
JuliaFormatter.remove_superfluous_whitespace!
— Methodremove_superfluous_whitespace!(fst::FST)
WHITESPACE
or PLACEHOLDER
that's directly followed by a NEWLINE
or INLINECOMMENT
node.JuliaFormatter.separate_kwargs_with_semicolon!
— Methodseparate_kwargs_with_semicolon!(fst::FST)
a = f(x, y = 3)
+end
JuliaFormatter.remove_superfluous_whitespace!
— Methodremove_superfluous_whitespace!(fst::FST)
WHITESPACE
or PLACEHOLDER
that's directly followed by a NEWLINE
or INLINECOMMENT
node.JuliaFormatter.separate_kwargs_with_semicolon!
— Methodseparate_kwargs_with_semicolon!(fst::FST)
a = f(x, y = 3)
->
@@ -112,6 +112,6 @@
->
-a = f(; x = 1, y = 2)
JuliaFormatter.short_to_long_function_def!
— Methodshort_to_long_function_def!(fst::FST, s::State)
f(arg1, arg2) = body
function f(arg2, arg2)
+a = f(; x = 1, y = 2)
JuliaFormatter.short_to_long_function_def!
— Methodshort_to_long_function_def!(fst::FST, s::State)
f(arg1, arg2) = body
function f(arg2, arg2)
body
-end
JuliaFormatter.unnestable_node
— Methodcst
is assumed to be a single child node. Returns true if the node is of the syntactic form {...}, [...], or (...)
.JuliaFormatter.walk
— Methodwalk(f, fst::FST, s::State)
fst
calling f
on each node.f
should return a value other than nothing
.s
) line_offset
. If this is not desired you should save the value before calling this function and restore it after.
Settings
This document was generated with Documenter.jl version 1.3.0 on Saturday 2 March 2024. Using Julia version 1.10.2.