domluna / JuliaFormatter.jl

An opinionated code formatter for Julia. Plot twist - the opinion is your own.
https://domluna.github.io/JuliaFormatter.jl/dev/
MIT License
582 stars 69 forks source link

Using JuliaFormatter as an executable (for usage with ALE) #483

Open AndreasAZiegler opened 3 years ago

AndreasAZiegler commented 3 years ago

I'm using ALE for linting and fixing for C++ and Python. I would love to use JuliaFormatter with ALE as well. As far as I understand it, JuliaFormatter has to be run as a single executable to make it work with ALE.

domluna commented 3 years ago

you might be able to make it work if include it with PackageCompiler

AndreasAZiegler commented 3 years ago

Thanks for your input @domluna. Could you elaborate a bit more what you mean? According to this description about PackageCompiler there are three ways how to use it. Which approach do you mean?

domluna commented 3 years ago

@kdheepak may know more about this since he was something similar working for the vim plugin

dpaetzel commented 3 weeks ago

I case other people find it helpful, I'm building a binary using this command

julia --project=. --startup-file=no -e 'using PackageCompiler; create_app(".", "compiled"; precompile_execution_file="src/other/precompile.jl", force=true)'

In order for that to work you likely first have to add PackageCompiler like so:

julia --project=. -e 'using Pkg; Pkg.add("PackageCompiler")'

The created binary then lies in compiled/bin/JuliaFormatter and can be called as path/to/repo/compiled/bin/JuliaFormatter somefile.jl to (very quickly) in-place format somefile.jl.

Note that I had to perform two minor fixes to get it working, though, which can be seen here.

(I'm still on v1.0.62 right now due to the issues with v2.)

105 is also related, I guess.

I then hooked this up to my Emacs so that upon saving the current file is formatted.