API Documentation

JuliaFormatter.DefaultStyleType
DefaultStyle

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

JuliaFormatter.YASStyleType
YASStyle

This style is EXPERIMENTAL !!!

Formatting style based on https://github.com/jrevels/YASGuide.

Recommended options are:

  • always_for_in = true,
  • whitespace_ops_in_indices = true,
  • whitespace_typedefs = false,
  • remove_extra_newlines = true,
JuliaFormatter.formatMethod
format(
    paths; # a path or collection of paths
    indent::Integer = 4,
    margin::Integer = 92,
    overwrite::Bool = true,
    verbose::Bool = false,
    always_for_in::Bool = false,
    remove_extra_newlines = false,
    style = DefaultStyle(),
)

Recursively descend into files and directories, formatting any .jl files by calling format_file on them.

JuliaFormatter.format_fileMethod
format_file(
    filename::AbstractString;
    overwrite::Bool = true,
    verbose::Bool = false,
    indent::Integer = 4,
    margin::Integer = 92,
    always_for_in::Bool = false,
    whitespace_typedefs::Bool = false,
    whitespace_ops_in_indices::Bool = false,
    remove_extra_newlines::Bool = false,
    style::AbstractStyle = DefaultStyle(),
)

Formats the contents of filename assuming it's a Julia source file.

File Options

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

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

Formatting Options

See format_text for description of formatting options.

JuliaFormatter.format_textMethod
format_text(
    text::AbstractString;
    indent::Int = 4,
    margin::Int = 92,
    always_for_in::Bool = false,
    whitespace_typedefs::Bool = false,
    whitespace_ops_in_indices::Bool = false,
    remove_extra_newlines::Bool = false,
    style::AbstractStyle = DefaultStyle(),
)::String

Formats a Julia source passed in as a string, returning the formatted code as another string.

Formatting Options

indent - the number of spaces used for an indentation.

margin - the maximum length of a line. Code exceeding this margin will be formatted across multiple lines.

If always_for_in is true = is always replaced with in if part of a for loop condition. For example, for i = 1:10 will be transformed to for i in 1:10.

If whitespace_typedefs is true, whitespace is added for type definitions. Make this true if you prefer Union{A <: B, C} to Union{A<:B,C}.

If whitespace_ops_in_indices is true, whitespace is added for binary operations in indices. Make this true if you prefer arr[a + b] to arr[a+b]. Additionally, if there's a colon : involved, parenthesis will be added to the LHS and RHS.

Example: arr[(i1 + i2):(i3 + i4)] instead of arr[i1+i2:i3+i4].

If remove_extra_newlines is true superflous newlines will be removed. For example:

a = 1



b = 2

is rewritten as

a = 1

b = 2
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.