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`.
-------------------------------------------------------------------------------
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*

View File

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

View File

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

View File

@ -159,8 +159,10 @@ formatting.
* [ruumba](https://github.com/ericqweinstein/ruumba)
* Erlang
* [SyntaxErl](https://github.com/ten0s/syntaxerl)
* [dialyzer](http://erlang.org/doc/man/dialyzer.html)
* [elvis](https://github.com/inaka/elvis) :floppy_disk:
* [erlc](http://erlang.org/doc/man/erlc.html)
* [erlfmt](https://github.com/WhatsApp/erlfmt)
* Fish
* fish [-n flag](https://linux.die.net/man/1/fish)
* [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(''))