FIX: use mix from the project root directory (#1954)
* FIX: use mix from the project root directory * Move find root project function to autoloaded handlers * add tests for #ale#handlers#elixr#FindMixProjectRoot
This commit is contained in:
parent
ea49cc759f
commit
bf1ac8e822
@ -29,9 +29,16 @@ function! ale_linters#elixir#credo#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#elixir#credo#GetCommand(buffer) abort
|
||||||
|
let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
|
||||||
|
|
||||||
|
return ale#path#CdString(l:project_root)
|
||||||
|
\ . ' mix help credo && mix credo suggest --format=flycheck --read-from-stdin %s'
|
||||||
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('elixir', {
|
call ale#linter#Define('elixir', {
|
||||||
\ 'name': 'credo',
|
\ 'name': 'credo',
|
||||||
\ 'executable': 'mix',
|
\ 'executable': 'mix',
|
||||||
\ 'command': 'mix help credo && mix credo suggest --format=flycheck --read-from-stdin %s',
|
\ 'command_callback': 'ale_linters#elixir#credo#GetCommand',
|
||||||
\ 'callback': 'ale_linters#elixir#credo#Handle',
|
\ 'callback': 'ale_linters#elixir#credo#Handle',
|
||||||
\})
|
\})
|
||||||
|
@ -25,10 +25,17 @@ function! ale_linters#elixir#dialyxir#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#elixir#dialyxir#GetCommand(buffer) abort
|
||||||
|
let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
|
||||||
|
|
||||||
|
return ale#path#CdString(l:project_root)
|
||||||
|
\ . ' mix help dialyzer && mix dialyzer'
|
||||||
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('elixir', {
|
call ale#linter#Define('elixir', {
|
||||||
\ 'name': 'dialyxir',
|
\ 'name': 'dialyxir',
|
||||||
\ 'executable': 'mix',
|
\ 'executable': 'mix',
|
||||||
\ 'command': 'mix help dialyzer && mix dialyzer',
|
\ 'command_callback': 'ale_linters#elixir#dialyxir#GetCommand',
|
||||||
\ 'callback': 'ale_linters#elixir#dialyxir#Handle',
|
\ 'callback': 'ale_linters#elixir#dialyxir#Handle',
|
||||||
\})
|
\})
|
||||||
|
|
||||||
|
@ -29,10 +29,17 @@ function! ale_linters#elixir#dogma#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#elixir#dogma#GetCommand(buffer) abort
|
||||||
|
let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
|
||||||
|
|
||||||
|
return ale#path#CdString(l:project_root)
|
||||||
|
\ . ' mix help dogma && mix dogma %s --format=flycheck'
|
||||||
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('elixir', {
|
call ale#linter#Define('elixir', {
|
||||||
\ 'name': 'dogma',
|
\ 'name': 'dogma',
|
||||||
\ 'executable': 'mix',
|
\ 'executable': 'mix',
|
||||||
\ 'command': 'mix help dogma && mix dogma %s --format=flycheck',
|
\ 'command_callback': 'ale_linters#elixir#dogma#GetCommand',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
\ 'callback': 'ale_linters#elixir#dogma#Handle',
|
\ 'callback': 'ale_linters#elixir#dogma#Handle',
|
||||||
\})
|
\})
|
||||||
|
@ -29,18 +29,8 @@ function! ale_linters#elixir#mix#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#elixir#mix#FindProjectRoot(buffer) abort
|
|
||||||
let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs')
|
|
||||||
|
|
||||||
if !empty(l:mix_file)
|
|
||||||
return fnamemodify(l:mix_file, ':p:h')
|
|
||||||
endif
|
|
||||||
|
|
||||||
return '.'
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! ale_linters#elixir#mix#GetCommand(buffer) abort
|
function! ale_linters#elixir#mix#GetCommand(buffer) abort
|
||||||
let l:project_root = ale_linters#elixir#mix#FindProjectRoot(a:buffer)
|
let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)
|
||||||
|
|
||||||
let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
|
let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
|
||||||
|
|
||||||
|
13
autoload/ale/handlers/elixir.vim
Normal file
13
autoload/ale/handlers/elixir.vim
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
" Author: Matteo Centenaro (bugant) - https://github.com/bugant
|
||||||
|
"
|
||||||
|
" Description: find the root directory for an elixir project that uses mix
|
||||||
|
|
||||||
|
function! ale#handlers#elixir#FindMixProjectRoot(buffer) abort
|
||||||
|
let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs')
|
||||||
|
|
||||||
|
if !empty(l:mix_file)
|
||||||
|
return fnamemodify(l:mix_file, ':p:h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '.'
|
||||||
|
endfunction
|
3
test/command_callback/elixir_paths/mix_project/mix.exs
Normal file
3
test/command_callback/elixir_paths/mix_project/mix.exs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
defmodule Test.MixProject do
|
||||||
|
# fake mix project file
|
||||||
|
end
|
@ -17,3 +17,10 @@ Execute(The default mix command should be correct):
|
|||||||
\ ale#path#CdString(ale#path#Simplify(g:dir . '/mix_paths/wrapped_project'))
|
\ ale#path#CdString(ale#path#Simplify(g:dir . '/mix_paths/wrapped_project'))
|
||||||
\ . g:env_prefix
|
\ . g:env_prefix
|
||||||
\ . 'mix compile %s'
|
\ . 'mix compile %s'
|
||||||
|
|
||||||
|
Execute(The FindMixProjectRoot should detect the project root directory via mix.exs):
|
||||||
|
silent execute 'file ' . fnameescape(g:dir . '/elixir_paths/mix_project/lib/app.ex')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale#path#Simplify(g:dir . '/elixir_paths/mix_project'),
|
||||||
|
\ ale#handlers#elixir#FindMixProjectRoot(bufnr(''))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user