Configuration File
Since v0.4.3, JuliaFormatter offers .prettierrc-style configuration file support.
When JuliaFormatter is called, it will look for .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. If found, the configurations in the file will override any options passed to JuliaFormatter's functions.
Specifying options
In .JuliaFormatter.toml, you can specify any of the formatting options in TOML. For example, if somedir/.JuliaFormatter.toml contains
indent = 2
margin = 100then files under somedir will be formatted with 2 spaces of indentation and a maximum line length of 100.
Configuration files also admit some extra options that are not formatting-related, such as ignore. See File Options for more details.
Search path
.JuliaFormatter.toml will be searched up from the directory of the file being formatted. So if you have:
dir
├─ .JuliaFormatter.toml
├─ code.jl
└─ subdir
└─ sub_code.jlthen:
format("subdir/sub_code.jl")will take its configuration fromdir/.JuliaFormatter.toml; andformat("dir")will format bothdir/code.jlanddir/subdir/sub_code.jlaccording to the same configuration.
If there are multiple .JuliaFormatter.toml files, the deepest configuration takes precedence. For example, if you have
dir
├─ .JuliaFormatter.toml
├─ code.jl
├─ subdir1
│ ├─ .JuliaFormatter.toml
│ └─ sub_code1.jl
└─ subdir2
└─ sub_code2.jland call format("dir"), then
code.jlandsub_code2.jlwill be formatted according to the rules defined indir/.JuliaFormatter.toml, whereassub_code1.jlwill be formatted according todir/subdir1/.JuliaFormatter.toml.