Merge pull request #1410 from fribmendes/frm/mix_format_options

Allow passing options to mix_format
This commit is contained in:
w0rp 2018-03-18 17:36:33 +00:00 committed by GitHub
commit 92612a9eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'
@ -18,3 +19,14 @@ Execute(The mix_format callback should return the correct default values):
\ },
\ 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(''))