summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2021-01-13 14:04:58 +0900
committerGitHub <noreply@github.com>2021-01-13 14:04:58 +0900
commit012348582c72716c8712e65d2c8456b1c3c2b42c (patch)
tree6ec3bf4046f55f428029d923c758f1c7f1eba419
parent12d28ca34f50f2c359ac71e349d41bd1a43a5f3a (diff)
parent62f2c6d3261af41ef01db6868724881fd6eebccc (diff)
downloadale-012348582c72716c8712e65d2c8456b1c3c2b42c.zip
Merge pull request #3531 from pinicarus/custom-erlc-executable
Custom erlc executable
-rw-r--r--ale_linters/erlang/erlc.vim16
-rw-r--r--doc/ale-erlang.txt8
-rw-r--r--test/command_callback/test_erlang_erlc_command_callback.vader40
3 files changed, 60 insertions, 4 deletions
diff --git a/ale_linters/erlang/erlc.vim b/ale_linters/erlang/erlc.vim
index a83bacc3..e78dc341 100644
--- a/ale_linters/erlang/erlc.vim
+++ b/ale_linters/erlang/erlc.vim
@@ -1,14 +1,22 @@
" Author: Magnus Ottenklinger - https://github.com/evnu
+let g:ale_erlang_erlc_executable = get(g:, 'ale_erlang_erlc_executable', 'erlc')
let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
+function! ale_linters#erlang#erlc#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'erlang_erlc_executable')
+endfunction
+
function! ale_linters#erlang#erlc#GetCommand(buffer) abort
let l:output_file = ale#util#Tempname()
call ale#command#ManageFile(a:buffer, l:output_file)
- return 'erlc -o ' . ale#Escape(l:output_file)
- \ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
- \ . ' %t'
+ let l:command = ale#Escape(ale_linters#erlang#erlc#GetExecutable(a:buffer))
+ \ . ' -o ' . ale#Escape(l:output_file)
+ \ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
+ \ . ' %t'
+
+ return l:command
endfunction
function! ale_linters#erlang#erlc#Handle(buffer, lines) abort
@@ -90,7 +98,7 @@ endfunction
call ale#linter#Define('erlang', {
\ 'name': 'erlc',
-\ 'executable': 'erlc',
+\ 'executable': function('ale_linters#erlang#erlc#GetExecutable'),
\ 'command': function('ale_linters#erlang#erlc#GetCommand'),
\ 'callback': 'ale_linters#erlang#erlc#Handle',
\})
diff --git a/doc/ale-erlang.txt b/doc/ale-erlang.txt
index 38762f08..9ee9a51d 100644
--- a/doc/ale-erlang.txt
+++ b/doc/ale-erlang.txt
@@ -46,6 +46,14 @@ g:ale_erlang_elvis_executable *g:ale_erlang_elvis_executable*
-------------------------------------------------------------------------------
erlc *ale-erlang-erlc*
+g:ale_erlang_erlc_executable *g:ale_erlang_erlc_executable*
+ *b:ale_erlang_erlc_executable*
+ Type: |String|
+ Default: `'erlc'`
+
+ This variable can be changed to specify the erlc executable.
+
+
g:ale_erlang_erlc_options *g:ale_erlang_erlc_options*
*b:ale_erlang_erlc_options*
Type: |String|
diff --git a/test/command_callback/test_erlang_erlc_command_callback.vader b/test/command_callback/test_erlang_erlc_command_callback.vader
new file mode 100644
index 00000000..7d659a07
--- /dev/null
+++ b/test/command_callback/test_erlang_erlc_command_callback.vader
@@ -0,0 +1,40 @@
+Before:
+ call ale#assert#SetUpLinterTest('erlang', 'erlc')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The default command should be correct.):
+ let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
+ let g:regex = 'erlc.\+-o.\+%t'
+ let g:matched = match(g:cmd, g:regex)
+
+ " match returns -1 if not found
+ AssertNotEqual
+ \ g:matched,
+ \ -1,
+ \ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
+
+Execute(The command should accept configured executable.):
+ let b:ale_erlang_erlc_executable = '/usr/bin/erlc'
+ let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
+ let g:regex = '/usr/bin/erlc.\+-o.\+%t'
+ let g:matched = match(g:cmd, g:regex)
+
+ " match returns -1 if not found
+ AssertNotEqual
+ \ g:matched,
+ \ -1,
+ \ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
+
+Execute(The command should accept configured options.):
+ let b:ale_erlang_erlc_options = '-I include'
+ let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
+ let g:regex = 'erlc.\+-o.\+-I include.\+%t'
+ let g:matched = match(g:cmd, g:regex)
+
+ " match returns -1 if not found
+ AssertNotEqual
+ \ g:matched,
+ \ -1,
+ \ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'