Add support for erlfmt fixer (#3602)

* Add support for `erlfmt`

* Add missing entry to table of contents

* Fix warnings

* Add missing tools to supported tools
This commit is contained in:
Antoine Gagné 2021-02-28 08:31:44 -05:00 committed by GitHub
parent 038e4a8c31
commit 48fab99a0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,21 @@
" Author: AntoineGagne - https://github.com/AntoineGagne
" Description: Integration of erlfmt with ALE.
call ale#Set('erlang_erlfmt_executable', 'erlfmt')
call ale#Set('erlang_erlfmt_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('erlang_erlfmt_options', '')
function! ale#fixers#erlfmt#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'erlang_erlfmt', ['erlfmt'])
endfunction
function! ale#fixers#erlfmt#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'erlang_erlfmt_options')
let l:executable = ale#fixers#erlfmt#GetExecutable(a:buffer)
let l:command = ale#Escape(l:executable) . (empty(l:options) ? '' : ' ' . l:options) . ' %s'
return {
\ 'command': l:command
\}
endfunction

View file

@ -71,6 +71,26 @@ g:ale_erlang_erlc_options *g:ale_erlang_erlc_options*
or `-pa`. or `-pa`.
-------------------------------------------------------------------------------
erlfmt *ale-erlang-erlfmt*
g:ale_erlang_erlfmt_executable *g:ale_erlang_erlfmt_executable*
*b:ale_erlang_erlfmt_executable*
Type: |String|
Default: `'erlfmt'`
This variable can be changed to specify the erlfmt executable.
g:ale_erlang_erlfmt_options *g:ale_erlang_erlfmt_options*
*b:ale_erlang_erlfmt_options*
Type: |String|
Default: `''`
This variable controls additional parameters passed to `erlfmt`, such as
`--insert-pragma` or `--print-width`.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
syntaxerl *ale-erlang-syntaxerl* syntaxerl *ale-erlang-syntaxerl*

View file

@ -150,8 +150,10 @@ Notes:
* `ruumba` * `ruumba`
* Erlang * Erlang
* `SyntaxErl` * `SyntaxErl`
* `dialyzer`
* `elvis`!! * `elvis`!!
* `erlc` * `erlc`
* `erlfmt`
* Fish * Fish
* `fish` (-n flag) * `fish` (-n flag)
* `fish_indent` * `fish_indent`

View file

@ -2697,6 +2697,7 @@ documented in additional help files.
dialyzer..............................|ale-erlang-dialyzer| dialyzer..............................|ale-erlang-dialyzer|
elvis.................................|ale-erlang-elvis| elvis.................................|ale-erlang-elvis|
erlc..................................|ale-erlang-erlc| erlc..................................|ale-erlang-erlc|
erlfmt................................|ale-erlang-erlfmt|
syntaxerl.............................|ale-erlang-syntaxerl| syntaxerl.............................|ale-erlang-syntaxerl|
eruby...................................|ale-eruby-options| eruby...................................|ale-eruby-options|
ruumba................................|ale-eruby-ruumba| ruumba................................|ale-eruby-ruumba|

View file

@ -159,8 +159,10 @@ formatting.
* [ruumba](https://github.com/ericqweinstein/ruumba) * [ruumba](https://github.com/ericqweinstein/ruumba)
* Erlang * Erlang
* [SyntaxErl](https://github.com/ten0s/syntaxerl) * [SyntaxErl](https://github.com/ten0s/syntaxerl)
* [dialyzer](http://erlang.org/doc/man/dialyzer.html)
* [elvis](https://github.com/inaka/elvis) :floppy_disk: * [elvis](https://github.com/inaka/elvis) :floppy_disk:
* [erlc](http://erlang.org/doc/man/erlc.html) * [erlc](http://erlang.org/doc/man/erlc.html)
* [erlfmt](https://github.com/WhatsApp/erlfmt)
* Fish * Fish
* fish [-n flag](https://linux.die.net/man/1/fish) * fish [-n flag](https://linux.die.net/man/1/fish)
* [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html) * [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html)

View file

@ -0,0 +1,25 @@
Before:
Save b:ale_elm_format_executable
Save b:ale_elm_format_options
let b:ale_elm_format_executable = 'erlfmt'
let b:ale_elm_format_options = ''
After:
Restore
Execute(The erlfmt command should handle empty options):
AssertEqual
\ {
\ 'command': ale#Escape('erlfmt') . ' %s'
\ },
\ ale#fixers#erlfmt#Fix(bufnr(''))
Execute(The erlfmt command should handle custom options):
let b:ale_erlang_erlfmt_options = '--insert-pragma'
AssertEqual
\ {
\ 'command': ale#Escape('erlfmt') . ' --insert-pragma %s'
\ },
\ ale#fixers#erlfmt#Fix(bufnr(''))