From 66f2bb0c604d606624aa575973a517bd779d4fc7 Mon Sep 17 00:00:00 2001 From: Tamas Hakkel Date: Mon, 30 Nov 2026 22:00:41 +0100 Subject: [PATCH] Extend description of JuliaFormatter.jl and add Runic.jl - Add mentions to styles supported by JuliaFormatter.jl, and example to customize a predefined style - Add example for CLI use of JuliaFormatter.jl - Add Runic.jl subsection --- src/sharing/index.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/sharing/index.md b/src/sharing/index.md index e97b3e9..f066918 100644 --- a/src/sharing/index.md +++ b/src/sharing/index.md @@ -161,15 +161,26 @@ For local coverage analysis, [LocalCoverage.jl](https://github.com/JuliaCI/Local ## Style To make your code easy to read, it is essential to follow a consistent set of guidelines. -The official [style guide](https://docs.julialang.org/en/v1/manual/style-guide/) is very short, so most people use third party style guides like [BlueStyle](https://github.com/JuliaDiff/BlueStyle) or [SciMLStyle](https://github.com/SciML/SciMLStyle). +The official [style guide](https://docs.julialang.org/en/v1/manual/style-guide/) is very short, so most people use third party style guides like [BlueStyle](https://github.com/JuliaDiff/BlueStyle), [SciMLStyle](https://github.com/SciML/SciMLStyle), or [YASGuide](https://github.com/jrevels/YASGuide). -[JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) is an automated formatter for Julia files which can help you enforce the style guide of your choice. +### JuliaFormatter.jl + +[JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) is an automated formatter for Julia files which can help you enforce the style of your choice, being either a predefined style (["default"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/default_style/), ["blue"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/blue_style/), ["sciml"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/sciml_style/), or ["yas"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/yas_style/)) or a customized version of them. Just add a file `.JuliaFormatter.toml` at the root of your repository, containing a single line like ```toml style = "blue" ``` +To override the defaults of the chosen style, you can add additional lines: + +```toml +style = "blue" +indent = 2 +margin = 100 +remove_extra_newlines = false +``` + Then, the package directory will be formatted in the BlueStyle whenever you call ```>format @@ -177,6 +188,15 @@ using JuliaFormatter JuliaFormatter.format(MyAwesomePackage) ``` +Or you can install it as a command-line application: +```bash +# Install it once with: +julia -e 'using Pkg; Pkg.Apps.add("JuliaFormatter")' + +# Then you can use it to format all files in a directory with multiple threads: +jlfmt --threads=6 -- --inplace -v src/ +``` + {% %} The [default formatter](https://www.julia-vscode.org/docs/stable/userguide/formatter/) falls back on JuliaFormatter.jl. @@ -187,6 +207,20 @@ The [default formatter](https://www.julia-vscode.org/docs/stable/userguide/forma You can format code automatically in GitHub pull requests with the [`julia-format` action](https://github.com/julia-actions/julia-format), or add the formatting check directly to your test suite. {% %} +### Runic.jl + +Another approach, taken by [Runic.jl](https://github.com/fredrikekre/Runic.jl), is not to allow any customization, and format the code with a fixed set of rules (_"A code formatter with rules set in stone."_). It is known for its ease of use and very fast execution. + +Run the following to install and run as a command-line application: +```bash +# Install it once as a Julia App: +julia -e 'using Pkg; Pkg.Apps.add("Runic")' + +# Run this to format all files in-place in the current directory (recursively) +runic --inplace . +``` + + ## Code quality Of course, there is more to code quality than just formatting.