Allow passing options to mix_format

This commit is contained in:
Fernando Mendes 2018-03-08 14:37:56 +00:00
parent 0a0535546f
commit 6320ce6674
4 changed files with 36 additions and 4 deletions

View File

@ -1,16 +1,23 @@
" Author: carakan <carakan@gmail.com>
" Author: carakan <carakan@gmail.com>, Fernando Mendes <fernando@mendes.codes>
" Description: Fixing files with elixir formatter 'mix format'.
call ale#Set('elixir_mix_executable', 'mix')
call ale#Set('elixir_mix_format_options', '')
function! ale#fixers#mix_format#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'elixir_mix_executable')
endfunction
function! ale#fixers#mix_format#GetCommand(buffer) abort
let l:executable = ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
let l:options = ale#Var(a:buffer, 'elixir_mix_format_options')
return l:executable . ' format ' . l:options . ' %t'
endfunction
function! ale#fixers#mix_format#Fix(buffer) abort
return {
\ 'command': ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
\ . ' format %t',
\ 'command': ale#fixers#mix_format#GetCommand(a:buffer),
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -13,6 +13,18 @@ g:ale_elixir_mix_options *g:ale_elixir_mix_options*
This variable can be changed to specify the mix executable.
===============================================================================
mix_format *ale-elixir-mix-format*
g:ale_elixir_mix_format_options *g:ale_elixir_mix_format_options*
*b:ale_elixir_mix_format_options*
Type: |String|
Default: `''`
This variable can be changed to specify the mix options passed to the
mix_format fixer
===============================================================================
dialyxir *ale-elixir-dialyxir*

View File

@ -59,6 +59,7 @@ CONTENTS *ale-contents*
hadolint............................|ale-dockerfile-hadolint|
elixir................................|ale-elixir-options|
mix.................................|ale-elixir-mix|
mix_format..........................|ale-elixir-mix-format|
dialyxir............................|ale-elixir-dialyxir|
elm...................................|ale-elm-options|
elm-format..........................|ale-elm-elm-format|

View File

@ -1,6 +1,7 @@
Before:
call ale#test#SetDirectory('/testplugin/test/fixers')
Save g:ale_elixir_mix_executable
Save g:ale_elixir_mix_format_options
let g:ale_elixir_mix_executable = 'xxxinvalid'
@ -14,7 +15,18 @@ Execute(The mix_format callback should return the correct default values):
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' format %t',
\ . ' format %t',
\ },
\ ale#fixers#mix_format#Fix(bufnr(''))
Execute(The mix_format callback should include the correct format options):
let g:ale_elixir_mix_format_options = 'invalid_options'
call ale#test#SetFilename('../elixir-test-files/testfile.ex')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' format invalid_options %t',
\ },
\ ale#fixers#mix_format#Fix(bufnr(''))