Julia code formatter / code beautifier


#1

Hello,

Code formatting is an important task to keep code more easily understandable.

Go have gofmt
Rust have rustfmt
Python have black

I wonder if there’s an active project for such task in Julia.

I’ve found https://github.com/invenia/JuliaFormat.jl from @invenia but it doesn’t seem to be maintained any more.

I wonder what are opinions of core (Base) Julia maintainers about such tools?

Is there a chance to have such tools be very well maintained and be used in Base code?

I also wonder why linter such as https://github.com/tonyhffong/Lint.jl is not currently used in Base (according https://github.com/JuliaLang/julia/blob/master/.travis.yml )

Kind regards


#2

We have a code formatter in the julia VS Code extension that works.

That code is currently being factored out into https://github.com/ZacLN/DocumentFormat.jl. The linting stuff in the VS Code extension is moving into https://github.com/ZacLN/StaticLint.jl.

All of this work is based on CSTParser.jl, which is actively maintained and also used by stuff that Julia Computing is putting out (e.g. femtocleaner).


#3

Is there a VS Code prerelease that works on Julia 0.7 without the highly annoying deprecation messages?


#4

No, we don’t have a 0.7 compatible version at this point.


#5

It will be great to have an online Julia code formatter (an Heroku app or any web apps framework compatible with Julia.

So code samples could be better formatted using such a service.


#6

VSCode is interesting. I am a big fan of Atom, and there is a really nice style checker for Python. Little warning trianges appear on the lines. This uses ‘pycodestyle’

Somethign similar for Julia woudl be most excellent. Happy to offer to test!


#7

So what should I do in VS code to

  • automatically indent my code (if, for and while loops…)
  • automatically add space to expressions such as a=b+2 to a = b + 2

?

I haven’t found a clear explanation, even in this thread (Auto)-formatting code?

A Github bot which could create PR to reformat code could be a very nice feature to have.


#8

Select the text you want to format, then execute the command “format selection” (or the precise name).


#9

Thanks @davidanthoff