The latest (1.5.0+) julia-vscode plugin already supports JuliaFormatter.jl as its default formatter.
This plugin will be deprecated. If you want to continue using some of its features, have a look at 0h7z/vscode-julia-format.
This is a Julia language formatter using the
JuliaFormatter.jl package. The
Julia extension
uses the DocumentFormat
package. They differ by some decisions.
- 
Though this extension will try to install it, we still recommend that you install JuliaFormatter.jlbefore installing this extension. To do this, open the REPL and type]add JuliaFormatter It is better to install the latest version of JuliaFormatter, since some settings require that.
This extension contributes the following settings:
- juliaFormatter.overwriteFlags: Whether to overwrite the settings of the specified style with the- JuliaFormatterflags specified in vs-code's settings.- falseby default.
- juliaFormatter.style: Formatting styles. Choose from:- 'default',- 'yas', and- 'blue'.
- juliaFormatter.compile: Control the compilation level of Julia. Available values are- 'min'or- 'all'.
- juliaFormatter.margin: The maximum number of characters of code on a single line. Lines over the limit will be wrapped if possible. There are cases where lines cannot be wrapped and they will still end up wider than the requested margin.- 92by default.
- juliaFormatter.indent: The number of spaces used for an indentation.- 4by default.
- juliaFormatter.alwaysForIn: Always replaces- =with- infor- forloops. For example,- for i = 1:10will be transformed to- for i in 1:10.- falseby default.
- juliaFormatter.whitespaceTypedefs: If- true, whitespace is added for type definitions. Make this- trueif you prefer- Union{A <: B, C}to- Union{A<:B,C}.
- juliaFormatter.whitespaceOpsInIndices: If- true, whitespace is added for binary operations in indices. Make this- trueif you prefer- arr[a + b]to- arr[a+b].
- juliaFormatter.removeExtraNewlines: If- true, superflous newlines will be removed.
- juliaFormatter.importToUsing: If- true,- importexpressions are rewritten to- usingexpressions.
- juliaFormatter.pipeToFunctionCall: If- true,- x |> fis rewritten to- f(x).
- juliaFormatter.shortToLongFunctionDef: Transforms a short function definition to a long function definition.
- juliaFormatter.alwaysUseReturn: If- true,- returnwill be prepended to the last expression where applicable in function definitions, macro definitions, and do blocks.
- juliaFormatter.whitespaceInKwargs: If- true,- =in keyword arguments will be surrounded by whitespace.
- juliaFormatter.annotateUntypedFieldsWithAny: If- true, Annotates fields in a type definitions with- ::Anyif no type annotation is provided (Requires- JuliaFormatter.jl v0.6.3).
- juliaFormatter.formatDocstrings: If- true, format code docstrings with the same options used for the code source.
- juliaFormatter.alignAssignment: If- true, align the- =-like operators. This covers variable assignments and short definition functions.
- juliaFormatter.alignStructField: If- true, align struct field definitions to- ::or- =, whichever has higher precedence.
- juliaFormatter.alignConditional: If- true, align conditional expressions to either- ?,- :, or both.
- juliaFormatter.alignPairArrow: If- true, align pair arrows (- =>).
- juliaFormatter.conditionalToIf: If the conditional- E ? A : Bexceeds the maximum margin converts it into the equivalent- ifblock.
- juliaFormatter.normalizeLineEndings: Normalize line endings.
- juliaFormatter.systemImagePath: The path to the sysimage to use when launching the Julia process that will format a file. If empty, no sysimage will be used. Read the PackageCompiler.jl documentation to learn why and how to create a sysimage. (Tl;dr a sysimage is a snapshot of the compiled functions in a Julia session, which can be reused to nearly eliminate the long compilation times Julia tends to suffer from. Using a sysimage can vastly reduce the time it takes to format files.)
For more detailed explanation of these settings, please go to its official docs.
It is recommended to use this extension with the Format in context menus extension (not an ad!). It allows formatting multiple files at a time.
If you want to use this extension instead of the Julia extension to format your file, you may want to put
"[julia]": {
    "editor.defaultFormatter": "singularitti.vscode-julia-formatter"
},in the editor's settings.json.
See CHANGELOG.md for release notes.
I extend my heartfelt gratitude to the Python Docstring Formatter Extension which has significantly inspired the development of this extension.