summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/vim/vint.vim29
-rw-r--r--doc/ale-vim.txt8
-rw-r--r--test/command_callback/test_vint_command_callback.vader39
3 files changed, 65 insertions, 11 deletions
diff --git a/ale_linters/vim/vint.vim b/ale_linters/vim/vint.vim
index dfa00dc0..cf2d4afd 100644
--- a/ale_linters/vim/vint.vim
+++ b/ale_linters/vim/vint.vim
@@ -2,31 +2,38 @@
" Description: This file adds support for checking Vim code with Vint.
" This flag can be used to change enable/disable style issues.
-let g:ale_vim_vint_show_style_issues =
-\ get(g:, 'ale_vim_vint_show_style_issues', 1)
-let s:enable_neovim = has('nvim') ? ' --enable-neovim ' : ''
+call ale#Set('vim_vint_show_style_issues', 1)
+call ale#Set('vim_vint_executable', 'vint')
+let s:enable_neovim = has('nvim') ? ' --enable-neovim' : ''
let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})"'
+function! ale_linters#vim#vint#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'vim_vint_executable')
+endfunction
+
function! ale_linters#vim#vint#VersionCommand(buffer) abort
+ let l:executable = ale_linters#vim#vint#GetExecutable(a:buffer)
+
" Check the Vint version if we haven't checked it already.
- return !ale#semver#HasVersion('vint')
- \ ? 'vint --version'
+ return !ale#semver#HasVersion(l:executable)
+ \ ? ale#Escape(l:executable) . ' --version'
\ : ''
endfunction
function! ale_linters#vim#vint#GetCommand(buffer, version_output) abort
- let l:version = ale#semver#GetVersion('vint', a:version_output)
+ let l:executable = ale_linters#vim#vint#GetExecutable(a:buffer)
+ let l:version = ale#semver#GetVersion(l:executable, a:version_output)
let l:can_use_no_color_flag = empty(l:version)
\ || ale#semver#GTE(l:version, [0, 3, 7])
let l:warning_flag = ale#Var(a:buffer, 'vim_vint_show_style_issues') ? '-s' : '-w'
- return 'vint '
- \ . l:warning_flag . ' '
- \ . (l:can_use_no_color_flag ? '--no-color ' : '')
+ return ale#Escape(l:executable)
+ \ . ' ' . l:warning_flag
+ \ . (l:can_use_no_color_flag ? ' --no-color' : '')
\ . s:enable_neovim
- \ . s:format
+ \ . ' ' . s:format
\ . ' %t'
endfunction
@@ -58,7 +65,7 @@ endfunction
call ale#linter#Define('vim', {
\ 'name': 'vint',
-\ 'executable': 'vint',
+\ 'executable_callback': 'ale_linters#vim#vint#GetExecutable',
\ 'command_chain': [
\ {'callback': 'ale_linters#vim#vint#VersionCommand', 'output_stream': 'stderr'},
\ {'callback': 'ale_linters#vim#vint#GetCommand', 'output_stream': 'stdout'},
diff --git a/doc/ale-vim.txt b/doc/ale-vim.txt
index 30ac3a16..772bad23 100644
--- a/doc/ale-vim.txt
+++ b/doc/ale-vim.txt
@@ -5,6 +5,14 @@ ALE Vim Integration *ale-vim-options*
===============================================================================
vint *ale-vim-vint*
+g:ale_vim_vint_executable *g:ale_vim_vint_executable*
+ *b:ale_vim_vint_executable*
+ Type: |String|
+ Default: `'vint'`
+
+ This option can be set to change the executable path for Vint.
+
+
g:ale_vim_vint_show_style_issues *g:ale_vim_vint_show_style_issues*
*b:ale_vim_vint_show_style_issues*
Type: |Number|
diff --git a/test/command_callback/test_vint_command_callback.vader b/test/command_callback/test_vint_command_callback.vader
new file mode 100644
index 00000000..ddf39f31
--- /dev/null
+++ b/test/command_callback/test_vint_command_callback.vader
@@ -0,0 +1,39 @@
+Before:
+ Save g:ale_vim_vint_executable
+
+ unlet! g:ale_vim_vint_executable
+
+ runtime ale_linters/vim/vint.vim
+
+ let b:command_tail = (has('nvim') ? ' --enable-neovim' : '')
+ \ . ' -f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})" %t'
+ call ale#semver#ResetVersionCache()
+
+After:
+ Restore
+
+ call ale#linter#Reset()
+ call ale#semver#ResetVersionCache()
+
+ unlet! b:bin_dir
+ unlet! b:executable
+
+Execute(The default command should be correct):
+ AssertEqual 'vint', ale_linters#vim#vint#GetExecutable(bufnr(''))
+ AssertEqual
+ \ ale#Escape('vint') .' --version',
+ \ ale_linters#vim#vint#VersionCommand(bufnr(''))
+ AssertEqual
+ \ ale#Escape('vint') .' -s --no-color' . b:command_tail,
+ \ ale_linters#vim#vint#GetCommand(bufnr(''), [])
+
+Execute(The executable should be configurable):
+ let g:ale_vim_vint_executable = 'foobar'
+
+ AssertEqual 'foobar', ale_linters#vim#vint#GetExecutable(bufnr(''))
+ AssertEqual
+ \ ale#Escape('foobar') .' --version',
+ \ ale_linters#vim#vint#VersionCommand(bufnr(''))
+ AssertEqual
+ \ ale#Escape('foobar') .' -s --no-color' . b:command_tail,
+ \ ale_linters#vim#vint#GetCommand(bufnr(''), [])