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:
parent
038e4a8c31
commit
48fab99a0a
6 changed files with 71 additions and 0 deletions
21
autoload/ale/fixers/erlfmt.vim
Normal file
21
autoload/ale/fixers/erlfmt.vim
Normal 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
|
|
@ -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*
|
||||
|
||||
|
|
|
@ -150,8 +150,10 @@ Notes:
|
|||
* `ruumba`
|
||||
* Erlang
|
||||
* `SyntaxErl`
|
||||
* `dialyzer`
|
||||
* `elvis`!!
|
||||
* `erlc`
|
||||
* `erlfmt`
|
||||
* Fish
|
||||
* `fish` (-n flag)
|
||||
* `fish_indent`
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
25
test/fixers/test_erlfmt_fixer_callback.vader
Normal file
25
test/fixers/test_erlfmt_fixer_callback.vader
Normal 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(''))
|
Reference in a new issue