Runic.jl: A code formatter with rules set in stone

Right, they shouldn’t cause a problem in the end though because Runic doesn’t hit the deprecations in JuliaSyntax (which is the source of these errors). You can silence them by

diff --git a/contrib/juliac-buildscript.jl b/contrib/juliac-buildscript.jl
index 50f96198c4..1745b21ad4 100644
--- a/contrib/juliac-buildscript.jl
+++ b/contrib/juliac-buildscript.jl
@@ -123,6 +123,7 @@ end
     mapreduce_empty(::typeof(identity), op::F, T) where {F} = reduce_empty(op, T)
     mapreduce_empty(::typeof(abs), op::F, T) where {F}     = abs(reduce_empty(op, T))
     mapreduce_empty(::typeof(abs2), op::F, T) where {F}    = abs2(reduce_empty(op, T))
+    depwarn(msg, funcsym; force::Bool=false) = nothing
 end
 @eval Base.Unicode begin
     function utf8proc_map(str::Union{String,SubString{String}}, options::Integer, chartransform::F = identity) where F

(xref add --trim option for generating smaller binaries by JeffBezanson · Pull Request #55047 · JuliaLang/julia · GitHub) or change Runic.jl/juliac/Makefile at 150ced92abc487b3ce47a0ce5d80aec501b6baab · fredrikekre/Runic.jl · GitHub from --unsafe-warn to --unsafe.

Runic version 1.0.0

Runic is now registered in General. There have been some changes to the style, and a bunch of bugs have been found and fixed after using Runic “in the wild”. I think it should be very robust at this point. Some packages which now uses Runic include Documenter.jl, Ferrite.jl, and Prometheus.jl.

Some things I want to mention:

Cheers!

Brilliant! Congratulations on such a comprehensive release :grinning:

I’m looking forward to adopting Runic (with a rules tweak or two) in my projects and wiring it up as an autoformatter for Julia code I write.

Runic versions 1.1, 1.2, 1.3

Runic versions 1.1, 1.2, and 1.3 are released, see CHANGELOG for all changes.

Runic now support ranged formatting with the new --lines=a:b option which enables more surgical formatting of code. Based on this I want to highlight the new Git integration provided by the git-runic script. git runic applies formatting only to your staged changes (but it can also be used to format the diff from multiple commits, see git runic -h for details). This enables incremental formatting of a code base as an alternative to going all in with Runic in a single large commit.

git-runic was contributed by @maleadt (thanks!) and is based on git-clang-format (git integration for clang-format). The following two blog posts give some more details about how git-clang-format (and thus git-runic) can be used:

Thanks!

I think @Imshk has a point. Both Go and Python follow the style that @Imshk suggested. I agree that everything inside the function body should be indented, but the argument list is not part of the function body.

Runic versions 1.4, 1.5, 1.6

Runic versions 1.4, 1.5, and 1.6 are released, see CHANGELOG for all changes and fixes.

Installation as a Pkg App

Runic can now (since version 1.4) be installed as a Pkg app by running:

pkg> app add Runic

This is now the preferred installation method (see updated installation and editor integration docs).

Updated JuliaSyntax version

Runic version 1.6 uses JuliaSyntax version 1 (instead of 0.4). This required quite large changes in Runic but shouldn’t mean that Runic format things differently (I have confirmed this on several large code bases which already user Runic).

Fixed “spec bugs”

Version 1.6.0 includes fixes for two “specification bugs”:

  • Trailing comma in single line anonymous function argument lists are now removed. For example (a, b,) -> a + b will now be formatted correctly as (a, b) -> a + b.
  • Runic enforces single space around keywords such as function, while, etc. However, for was previously not included in this formatting pass. Runic 1.6.0 will thus format e.g. for i in I as for i in I.

Both of these are rather unusual. In fact, across all the repos I tried Runic on, only one case of the former was detected.

Let me know here or on the issue tracker if something isn’t working correctly. Thanks!

Runic version 1.7

Runic version 1.7 is released, see CHANGELOG for all changes and fixes. The headline feature in this release is that Runic can now format Julia code inside docstrings and inside Markdown files.

Formatting Julia code blocks in docstrings

A new opt-in flag --docstrings (and matching docstrings::Bool keyword argument to Runic.format_file / Runic.format_string) formats Julia code embedded in docstrings:

runic --docstrings --inplace src/

Fenced ```julia, ```julia-repl, and ```jldoctest blocks have their contents run through Runic. In addition, all indented Markdown code blocks (including the leading method-signature block that many docstrings start with) are also formatted as Julia code. The --docstrings flag is also exposed through fredrikekre/runic-action and fredrikekre/runic-pre-commit.

Formatting Markdown files

Embedded Julia code in Markdown files can now formatted by rewriting the embedded Julia code blocks (same rules as --docstrings). Dispatch is by file extension, so an explicit path just works:

runic --inplace README.md

For directory walks, a new --extensions=<list> flag controls which files are collected (default jl):

runic --extensions=jl,md --inplace .

Stdin input can also be routed through the Markdown formatter by passing a virtual filename:

cat README.md | runic --stdin-filename=stdin.md

The --lines option is supported with block-granular semantics: any code block whose line range overlaps a --lines range is formatted in full; blocks outside are left untouched. Markdown file formatting is also available through fredrikekre/runic-action and fredrikekre/runic-pre-commit.

git-runic as a Pkg app

The git-runic Git integration (which applies Runic formatting incrementally by limiting it to lines added or modified in each commit) has been translated to Julia and is now shipped together with runic as part of the Pkg app. No more curl-ing a shell script:

pkg> app add Runic

This installs both runic and git-runic to ~/.julia/bin. With that directory in PATH, git runic can be invoked directly from any git repository.

Let me know here or on the issue tracker if something isn’t working correctly. Thanks!

ALT + SHIFT + F (on Windows) can only be tied to one formatter per file extension/format. For markdown files, is there an way to easily access both Markdown formatter and Runic? I imagine one of them will need to be manually called (CTRL + SHIFT + P then format, etc.) each time.

No idea, but sounds like a good opportunity to switch to Neovim.