Close #1315 - Make the vint executable configurable

This commit is contained in:
w0rp 2018-04-08 18:10:00 +01:00
parent f9ae58849a
commit 1123669839
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
3 changed files with 65 additions and 11 deletions

View File

@ -2,31 +2,38 @@
" Description: This file adds support for checking Vim code with Vint. " Description: This file adds support for checking Vim code with Vint.
" This flag can be used to change enable/disable style issues. " This flag can be used to change enable/disable style issues.
let g:ale_vim_vint_show_style_issues = call ale#Set('vim_vint_show_style_issues', 1)
\ get(g:, 'ale_vim_vint_show_style_issues', 1) call ale#Set('vim_vint_executable', 'vint')
let s:enable_neovim = has('nvim') ? ' --enable-neovim ' : '' let s:enable_neovim = has('nvim') ? ' --enable-neovim' : ''
let s:format = '-f "{file_path}:{line_number}:{column_number}: {severity}: {description} (see {reference})"' 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 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. " Check the Vint version if we haven't checked it already.
return !ale#semver#HasVersion('vint') return !ale#semver#HasVersion(l:executable)
\ ? 'vint --version' \ ? ale#Escape(l:executable) . ' --version'
\ : '' \ : ''
endfunction endfunction
function! ale_linters#vim#vint#GetCommand(buffer, version_output) abort 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) let l:can_use_no_color_flag = empty(l:version)
\ || ale#semver#GTE(l:version, [0, 3, 7]) \ || ale#semver#GTE(l:version, [0, 3, 7])
let l:warning_flag = ale#Var(a:buffer, 'vim_vint_show_style_issues') ? '-s' : '-w' let l:warning_flag = ale#Var(a:buffer, 'vim_vint_show_style_issues') ? '-s' : '-w'
return 'vint ' return ale#Escape(l:executable)
\ . l:warning_flag . ' ' \ . ' ' . l:warning_flag
\ . (l:can_use_no_color_flag ? '--no-color ' : '') \ . (l:can_use_no_color_flag ? ' --no-color' : '')
\ . s:enable_neovim \ . s:enable_neovim
\ . s:format \ . ' ' . s:format
\ . ' %t' \ . ' %t'
endfunction endfunction
@ -58,7 +65,7 @@ endfunction
call ale#linter#Define('vim', { call ale#linter#Define('vim', {
\ 'name': 'vint', \ 'name': 'vint',
\ 'executable': 'vint', \ 'executable_callback': 'ale_linters#vim#vint#GetExecutable',
\ 'command_chain': [ \ 'command_chain': [
\ {'callback': 'ale_linters#vim#vint#VersionCommand', 'output_stream': 'stderr'}, \ {'callback': 'ale_linters#vim#vint#VersionCommand', 'output_stream': 'stderr'},
\ {'callback': 'ale_linters#vim#vint#GetCommand', 'output_stream': 'stdout'}, \ {'callback': 'ale_linters#vim#vint#GetCommand', 'output_stream': 'stdout'},

View File

@ -5,6 +5,14 @@ ALE Vim Integration *ale-vim-options*
=============================================================================== ===============================================================================
vint *ale-vim-vint* 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* g:ale_vim_vint_show_style_issues *g:ale_vim_vint_show_style_issues*
*b:ale_vim_vint_show_style_issues* *b:ale_vim_vint_show_style_issues*
Type: |Number| Type: |Number|

View File

@ -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(''), [])