diff options
author | Colby Dehart <colbydehart@gmail.com> | 2018-06-02 13:03:56 -0400 |
---|---|---|
committer | Colby Dehart <colbydehart@gmail.com> | 2018-06-02 13:03:56 -0400 |
commit | 81739be0a04956458471f196874d4206b21e60fb (patch) | |
tree | f60fa72b4087a9492bfa5a6247ee9f5097ceaae9 | |
parent | d760558007631294673171451f72fc4c2f5a89a7 (diff) | |
download | ale-81739be0a04956458471f196874d4206b21e60fb.zip |
handled temp file and env variable correctly; added tests
-rw-r--r-- | ale_linters/elixir/mix.vim | 18 | ||||
-rw-r--r-- | test/handler/test_mix_handler.vader | 21 |
2 files changed, 35 insertions, 4 deletions
diff --git a/ale_linters/elixir/mix.vim b/ale_linters/elixir/mix.vim index d31dbb28..c4beb42d 100644 --- a/ale_linters/elixir/mix.vim +++ b/ale_linters/elixir/mix.vim @@ -1,5 +1,6 @@ " Author: evnu - https://github.com/evnu " Author: colbydehart - https://github.com/colbydehart +" Description: Mix compile checking for Elixir files function! ale_linters#elixir#mix#Handle(buffer, lines) abort " Matches patterns like the following: @@ -29,14 +30,23 @@ function! ale_linters#elixir#mix#Handle(buffer, lines) abort return l:output endfunction -function! ale_linters#elixir#mix#Command(buffer) abort - let l:project_dir = fnamemodify(ale#path#FindNearestFile(a:buffer, 'mix.exs'), ':h') - return 'cd ' . l:project_dir . ' && MIX_BUILD_PATH=/tmp/mix mix compile %s' +function! ale_linters#elixir#mix#GetCommand(buffer) abort + let l:project_root = fnamemodify(ale#path#FindNearestFile(a:buffer, 'mix.exs'), ':h') + + let l:temp_dir = ale#engine#CreateDirectory(a:buffer) + + let l:mix_build_path = has('win32') + \ ? 'set MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' && ' + \ : 'MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' ' + + return ale#path#CdString(l:project_root) + \ . l:mix_build_path + \ . ' mix compile %s' endfunction call ale#linter#Define('elixir', { \ 'name': 'mix', \ 'executable': 'mix', -\ 'command_callback': 'ale_linters#elixir#mix#Command', +\ 'command_callback': 'ale_linters#elixir#mix#GetCommand', \ 'callback': 'ale_linters#elixir#mix#Handle', \}) diff --git a/test/handler/test_mix_handler.vader b/test/handler/test_mix_handler.vader new file mode 100644 index 00000000..a5549b5d --- /dev/null +++ b/test/handler/test_mix_handler.vader @@ -0,0 +1,21 @@ +Before: + runtime ale_linters/elixir/mix.vim + +After: + call ale#linter#Reset() + +Execute(The mix handler should parse lines correctly): + + AssertEqual + \ [ + \ { + \ 'bufnr': 347, + \ 'lnum': 87, + \ 'col': 0, + \ 'text': 'undefined function update_in/4', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#elixir#mix#Handle(347, [ + \ '** (CompileError) apps/sim/lib/sim/server.ex:87: undefined function update_in/4' + \ ]) |