Command Line Interface
JuliaFormatter provides a command-line executable jlfmt for formatting Julia source code.
Installation
Install using Julia's app manager:
pkg> app add JuliaFormatterThis makes the jlfmt command available in your PATH.
Alternatively, invoke directly without installation:
julia -m JuliaFormatter [<options>] <path>...The CLI interface is designed to be compatible with Runic.jl's CLI where possible, making it easier to switch between formatters.
Quick Start
# Preview formatted output
jlfmt src/file.jl
# Check if files are already formatted with verbose mode
jlfmt --check -v src/
# Format files in-place with multiple threads
jlfmt --threads=6 -- --inplace -v src/
# Show diff without modifying
jlfmt --diff src/file.jlOptions
Run jlfmt --help for a complete list:
NAME
jlfmt - An opinionated code formatter for Julia.
SYNOPSIS
jlfmt [<options>] <path>...
jlfmt [<options>] -
... | jlfmt [<options>]
DESCRIPTION
`jlfmt` formats Julia source code using JuliaFormatter.jl.
This tool can also be invoked as `julia -m JuliaFormatter`.
OPTIONS
<path>...
Input path(s) (files and/or directories) to process. For directories,
all files (recursively) with the '*.jl' suffix are used as input files
(also '*.md', '*.jmd', '*.qmd' if --format-markdown is specified).
If no path is given, or if path is `-`, input is read from stdin.
-c, --check
Do not write output and exit with a non-zero code if the input is not
formatted correctly.
-d, --diff
Print the diff between the input and formatted output to stderr.
Requires `git` to be installed.
-h, --help
Print this message.
-i, --inplace
Format files in place.
-o <file>, --output=<file>
File to write formatted output to. If no output is given, or if the file
is `-`, output is written to stdout.
--stdin-filename=<filename>
Assumed filename when formatting from stdin. Used for error messages.
--config-dir=<path>
Directory path to use for .JuliaFormatter.toml config file lookup when
formatting from stdin. By default, stdin input does not use config files.
With this option, the formatter will search for .JuliaFormatter.toml in
the specified directory and its parent directories.
-v, --verbose
Enable verbose output.
--version
Print JuliaFormatter and julia version information.
--prioritize-config-file
Prioritize .JuliaFormatter.toml config file options over command-line options.
By default, command-line options override config file options. This flag
reverses that precedence, useful for language server integration where
project configuration should take precedence over editor settings.
FORMATTING OPTIONS
--style=<style>
Formatting style: "default", "yas", "blue", "sciml", or "minimal".
Default: "default"
--indent=<n>
Indentation width. Default: 4
--margin=<n>
Maximum line width. Default: 92
--format_markdown
Also format code blocks in Markdown files (.md, .jmd, .qmd).
--ignore=<pattern>
Ignore files matching the given pattern. Can be specified multiple times.
Patterns use glob-style matching (e.g., "*/test/*", "*.tmp").
--always_for_in / --no-always_for_in
Always use 'for x in' instead of 'for x =' or 'for x '.
Default: false
--whitespace_typedefs / --no-whitespace_typedefs
Add whitespace around '::' in type definitions.
Default: false
--remove_extra_newlines / --no-remove_extra_newlines
Remove extra newlines.
Default: false
--import_to_using / --no-import_to_using
Convert 'import' to 'using'.
Default: false
--pipe_to_function_call / --no-pipe_to_function_call
Convert pipe operator to function calls.
Default: false
--short_to_long_function_def / --no-short_to_long_function_def
Convert short function definitions to long form.
Default: false
--always_use_return / --no-always_use_return
Always add explicit 'return' statements.
Default: false
--whitespace_in_kwargs / --no-whitespace_in_kwargs
Add whitespace in keyword arguments.
Default: true
--format_docstrings / --no-format_docstrings
Format docstrings.
Default: false
--align_struct_field / --no-align_struct_field
Align struct field type annotations.
Default: false
--align_assignment / --no-align_assignment
Align assignment operators.
Default: false
--align_conditional / --no-align_conditional
Align conditional operators.
Default: false
--align_pair_arrow / --no-align_pair_arrow
Align pair arrows (=>).
Default: false
--trailing_comma / --no-trailing_comma
Add trailing commas.
Default: true
--trailing_zero / --no-trailing_zero
Add trailing zeros to floats.
Default: true
--normalize_line_endings=<mode>
Normalize line endings: "auto", "unix", or "windows".
Default: "auto"
EXAMPLES
Format a file and write to stdout:
jlfmt src/file.jl
Format a file in place:
jlfmt --inplace src/file.jl
Format all files in a directory with the verbose mode:
jlfmt --inplace --verbose src/
Check if a file is formatted:
jlfmt --check src/file.jl
Check if all files in a directory are formatted with multiple threads:
jlfmt --threads=4 -- --check src/
Show diff for formatting wtih 2-space indentations:
jlfmt --diff --indent=2 src/file.jl
Format from stdin (pipe):
echo 'f(x,y)=x+y' | jlfmt
Format from stdin (explicit):
jlfmt - < input.jl
Format from stdin using project config:
echo 'f(x,y)=x+y' | jlfmt --config-dir=./src
Use specific style:
jlfmt --style=blue src/file.jl
Combine options:
echo 'for i=1:10; end' | jlfmt --always_for_inConfiguration Files
jlfmt searches for .JuliaFormatter.toml configuration files starting from each input file's directory and walking up the directory tree.
By default, command-line options override configuration file settings:
# Use indent=2 even if config file specifies indent=4
jlfmt --indent=2 src/file.jlUse --prioritize-config-file to make configuration file settings take precedence (might be useful for language server integration):
jlfmt --prioritize-config-file --indent=2 src/file.jlConfiguration with stdin
When formatting from stdin, no configuration file is used by default. Use --config-dir to specify a directory for configuration file lookup:
# Format stdin using config from ./src directory
echo 'f(x,y)=x+y' | jlfmt --config-dir=./src
# Useful in editor integrations to respect project config
cat file.jl | jlfmt --config-dir=$(dirname file.jl)The formatter will search for .JuliaFormatter.toml in the specified directory and its parent directories, just like it does for regular file inputs.
Conventions
jlfmt follows standard CLI conventions:
- Exit code 0 on success
- Exit code 1 on formatting errors or when
--checkdetects unformatted files - Formatted output to stdout (default) or in-place with
--inplace - Error messages to stderr