From 1123669839c1656deb20f433fc672ca0abdda705 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 8 Apr 2018 18:10:00 +0100 Subject: [PATCH] Close #1315 - Make the vint executable configurable --- ale_linters/vim/vint.vim | 29 ++++++++------ doc/ale-vim.txt | 8 ++++ .../test_vint_command_callback.vader | 39 +++++++++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 test/command_callback/test_vint_command_callback.vader diff --git a/ale_linters/vim/vint.vim b/ale_linters/vim/vint.vim index dfa00dc..cf2d4af 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 30ac3a1..772bad2 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 0000000..ddf39f3 --- /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(''), [])