Merge pull request #1017 from carakan/elixir_format

`mix format` new fixer for elixir lang
This commit is contained in:
w0rp 2017-10-24 22:13:04 +01:00 committed by GitHub
commit 0e4dd95e5d
6 changed files with 60 additions and 0 deletions

View File

@ -27,6 +27,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['javascript', 'typescript'],
\ 'description': 'Apply eslint --fix to a file.',
\ },
\ 'mix_format': {
\ 'function': 'ale#fixers#mix_format#Fix',
\ 'suggested_filetypes': ['elixir'],
\ 'description': 'Apply mix format to a file.',
\ },
\ 'format': {
\ 'function': 'ale#fixers#format#Fix',
\ 'suggested_filetypes': ['elm'],

View File

@ -0,0 +1,16 @@
" Author: carakan <carakan@gmail.com>
" Description: Fixing files with elixir formatter 'mix format'.
call ale#Set('elixir_mix_executable', 'mix')
function! ale#fixers#mix_format#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'elixir_mix_executable')
endfunction
function! ale#fixers#mix_format#Fix(buffer) abort
return {
\ 'command': ale#Escape(ale#fixers#mix_format#GetExecutable(a:buffer))
\ . ' format %t',
\ 'read_temporary_file': 1,
\}
endfunction

17
doc/ale-elixir.txt Normal file
View File

@ -0,0 +1,17 @@
===============================================================================
ALE Elixir Integration *ale-elixir-options*
===============================================================================
mix *ale-elixir-mix*
g:ale_elixir_mix_options *g:ale_elixir_mix_options*
*b:ale_elixir_mix_options*
Type: |String|
Default: `'mix'`
This variable can be changed to specify the mix executable.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -48,6 +48,8 @@ CONTENTS *ale-contents*
dartanalyzer........................|ale-dart-dartanalyzer|
dockerfile............................|ale-dockerfile-options|
hadolint............................|ale-dockerfile-hadolint|
elixir................................|ale-elixir-options|
mix.................................|ale-elixir-mix|
elm...................................|ale-elm-options|
elm-format..........................|ale-elm-elm-format|
elm-make............................|ale-elm-elm-make|

View File

View File

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