summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/elixir/credo.vim9
-rw-r--r--ale_linters/elixir/dialyxir.vim9
-rw-r--r--ale_linters/elixir/dogma.vim9
-rw-r--r--ale_linters/elixir/mix.vim16
-rw-r--r--autoload/ale/handlers/elixir.vim13
-rw-r--r--test/command_callback/elixir_paths/mix_project/lib/foo.ex0
-rw-r--r--test/command_callback/elixir_paths/mix_project/mix.exs3
-rw-r--r--test/command_callback/test_elixir_mix_command_callbacks.vader7
8 files changed, 50 insertions, 16 deletions
diff --git a/ale_linters/elixir/credo.vim b/ale_linters/elixir/credo.vim
index af2ff48a..6e949677 100644
--- a/ale_linters/elixir/credo.vim
+++ b/ale_linters/elixir/credo.vim
@@ -29,9 +29,16 @@ function! ale_linters#elixir#credo#Handle(buffer, lines) abort
return l:output
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', {
\ 'name': 'credo',
\ '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',
\})
diff --git a/ale_linters/elixir/dialyxir.vim b/ale_linters/elixir/dialyxir.vim
index bba0ae14..d28d3c70 100644
--- a/ale_linters/elixir/dialyxir.vim
+++ b/ale_linters/elixir/dialyxir.vim
@@ -25,10 +25,17 @@ function! ale_linters#elixir#dialyxir#Handle(buffer, lines) abort
return l:output
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', {
\ 'name': 'dialyxir',
\ 'executable': 'mix',
-\ 'command': 'mix help dialyzer && mix dialyzer',
+\ 'command_callback': 'ale_linters#elixir#dialyxir#GetCommand',
\ 'callback': 'ale_linters#elixir#dialyxir#Handle',
\})
diff --git a/ale_linters/elixir/dogma.vim b/ale_linters/elixir/dogma.vim
index 71cf4f4c..dcfb6f28 100644
--- a/ale_linters/elixir/dogma.vim
+++ b/ale_linters/elixir/dogma.vim
@@ -29,10 +29,17 @@ function! ale_linters#elixir#dogma#Handle(buffer, lines) abort
return l:output
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', {
\ 'name': 'dogma',
\ 'executable': 'mix',
-\ 'command': 'mix help dogma && mix dogma %s --format=flycheck',
+\ 'command_callback': 'ale_linters#elixir#dogma#GetCommand',
\ 'lint_file': 1,
\ 'callback': 'ale_linters#elixir#dogma#Handle',
\})
diff --git a/ale_linters/elixir/mix.vim b/ale_linters/elixir/mix.vim
index 4552ace5..dc3c1818 100644
--- a/ale_linters/elixir/mix.vim
+++ b/ale_linters/elixir/mix.vim
@@ -29,18 +29,8 @@ function! ale_linters#elixir#mix#Handle(buffer, lines) abort
return l:output
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
- 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)
@@ -49,8 +39,8 @@ function! ale_linters#elixir#mix#GetCommand(buffer) abort
\ : 'MIX_BUILD_PATH=' . ale#Escape(l:temp_dir)
return ale#path#CdString(l:project_root)
- \ . l:mix_build_path
- \ . ' mix compile %s'
+ \ . l:mix_build_path
+ \ . ' mix compile %s'
endfunction
call ale#linter#Define('elixir', {
diff --git a/autoload/ale/handlers/elixir.vim b/autoload/ale/handlers/elixir.vim
new file mode 100644
index 00000000..91b75aac
--- /dev/null
+++ b/autoload/ale/handlers/elixir.vim
@@ -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
diff --git a/test/command_callback/elixir_paths/mix_project/lib/foo.ex b/test/command_callback/elixir_paths/mix_project/lib/foo.ex
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/elixir_paths/mix_project/lib/foo.ex
diff --git a/test/command_callback/elixir_paths/mix_project/mix.exs b/test/command_callback/elixir_paths/mix_project/mix.exs
new file mode 100644
index 00000000..419685ae
--- /dev/null
+++ b/test/command_callback/elixir_paths/mix_project/mix.exs
@@ -0,0 +1,3 @@
+defmodule Test.MixProject do
+ # fake mix project file
+end
diff --git a/test/command_callback/test_elixir_mix_command_callbacks.vader b/test/command_callback/test_elixir_mix_command_callbacks.vader
index 18fb13ed..9315a850 100644
--- a/test/command_callback/test_elixir_mix_command_callbacks.vader
+++ b/test/command_callback/test_elixir_mix_command_callbacks.vader
@@ -17,3 +17,10 @@ Execute(The default mix command should be correct):
\ ale#path#CdString(ale#path#Simplify(g:dir . '/mix_paths/wrapped_project'))
\ . g:env_prefix
\ . '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(''))