Width-sensitive formatter for Julia code. Inspired by gofmt, refmt, and black.
Note
Recent versions of JuliaFormatter (v2+) still have a number of rough edges! I'm putting a lot of effort into fixing these, but if you require absolute stability, please consider pinning the version of JuliaFormatter, and possibly downgrading to v1. In general if you are already happy with a given version of JuliaFormatter, you should pin it in your CI workflows etc. -- the only reason you should upgrade is if you want to take advantage of new features or bug fixes.
See also the Project Status section of the docs for more details.
pkg> add JuliaFormatterjulia> using JuliaFormatter
# Recursively formats all Julia files in the current directory
julia> format(".")
# Formats an individual file
julia> format_file("foo.jl")
# Formats a string (contents of a Julia file)
julia> format_text(str)Check out the docs for further description of the formatter and its options.
Starting from version 2.2.0, JuliaFormatter provides a command-line executable jlfmt.
To install:
pkg> app add JuliaFormatterUsage:
# Format a file and write to stdout
jlfmt src/file.jl
# Format a file in place
jlfmt --inplace src/file.jl
# Check if all files in a directory are already formatted with verbose mode
jlfmt --check -v src/
# Format all files in a directory with multiple threads
jlfmt --threads=6 -- --inplace -v src/
# Show diff without modifying files
jlfmt --diff src/file.jlRun jlfmt --help for more options.
Check out the CLI docs for further description of the formatter and its options.