Set the end column for some Vint problems

This commit is contained in:
w0rp 2017-08-26 17:23:20 +01:00
parent e13651c16d
commit b9cf450684
2 changed files with 53 additions and 4 deletions

View File

@ -36,6 +36,32 @@ function! ale_linters#vim#vint#GetCommand(buffer, version_output) abort
\ . ' %t' \ . ' %t'
endfunction endfunction
let s:word_regex_list = [
\ '\v^Undefined variable: ([^ ]+)',
\ '\v^Make the scope explicit like ...([^ ]+). ',
\ '\v^.*start with a capital or contain a colon: ([^ ]+)',
\ '\v.*instead of .(\=[=~]).',
\]
function! ale_linters#vim#vint#Handle(buffer, lines) abort
let l:loclist = ale#handlers#gcc#HandleGCCFormat(a:buffer, a:lines)
for l:item in l:loclist
let l:match = []
for l:regex in s:word_regex_list
let l:match = matchlist(l:item.text, l:regex)
if !empty(l:match)
let l:item.end_col = l:item.col + len(l:match[1]) - 1
break
endif
endfor
endfor
return l:loclist
endfunction
call ale#linter#Define('vim', { call ale#linter#Define('vim', {
\ 'name': 'vint', \ 'name': 'vint',
\ 'executable': 'vint', \ 'executable': 'vint',
@ -43,5 +69,5 @@ call ale#linter#Define('vim', {
\ {'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'},
\ ], \ ],
\ 'callback': 'ale#handlers#gcc#HandleGCCFormat', \ 'callback': 'ale_linters#vim#vint#Handle',
\}) \})

View File

@ -1,6 +1,10 @@
Execute(The vint handler should parse error messages correctly): Before:
:file! gxc.vim runtime ale_linters/vim/vint.vim
After:
call ale#linter#Reset()
Execute(The vint handler should parse error messages correctly):
AssertEqual AssertEqual
\ [ \ [
\ { \ {
@ -12,25 +16,44 @@ Execute(The vint handler should parse error messages correctly):
\ { \ {
\ 'lnum': 3, \ 'lnum': 3,
\ 'col': 17, \ 'col': 17,
\ 'end_col': 18,
\ 'text': 'Use robust operators ''==#'' or ''==?'' instead of ''=='' (see Google VimScript Style Guide (Matching))', \ 'text': 'Use robust operators ''==#'' or ''==?'' instead of ''=='' (see Google VimScript Style Guide (Matching))',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ { \ {
\ 'lnum': 3, \ 'lnum': 3,
\ 'col': 8, \ 'col': 8,
\ 'end_col': 15,
\ 'text': 'Make the scope explicit like ''l:filename'' (see Anti-pattern of vimrc (Scope of identifier))', \ 'text': 'Make the scope explicit like ''l:filename'' (see Anti-pattern of vimrc (Scope of identifier))',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ { \ {
\ 'lnum': 7, \ 'lnum': 7,
\ 'col': 8, \ 'col': 8,
\ 'end_col': 15,
\ 'text': 'Undefined variable: filename (see :help E738)', \ 'text': 'Undefined variable: filename (see :help E738)',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ {
\ 'lnum': 8,
\ 'col': 11,
\ 'end_col': 16,
\ 'text': 'E128: Function name must start with a capital or contain a colon: foobar (see ynkdir/vim-vimlparser)',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 9,
\ 'col': 12,
\ 'end_col': 13,
\ 'text': 'Use robust operators ''=~#'' or ''=~?'' instead of ''=~'' (see Google VimScript Style Guide (Matching))',
\ 'type': 'W',
\ },
\ ], \ ],
\ ale#handlers#gcc#HandleGCCFormat(347, [ \ ale_linters#vim#vint#Handle(bufnr(''), [
\ 'gcc.vim:1:1: warning: Use scriptencoding when multibyte char exists (see :help :script encoding)', \ 'gcc.vim:1:1: warning: Use scriptencoding when multibyte char exists (see :help :script encoding)',
\ 'gcc.vim:3:17: warning: Use robust operators `==#` or `==?` instead of `==` (see Google VimScript Style Guide (Matching))', \ 'gcc.vim:3:17: warning: Use robust operators `==#` or `==?` instead of `==` (see Google VimScript Style Guide (Matching))',
\ 'gcc.vim:3:8: style_problem: Make the scope explicit like `l:filename` (see Anti-pattern of vimrc (Scope of identifier))', \ 'gcc.vim:3:8: style_problem: Make the scope explicit like `l:filename` (see Anti-pattern of vimrc (Scope of identifier))',
\ 'gcc.vim:7:8: warning: Undefined variable: filename (see :help E738)', \ 'gcc.vim:7:8: warning: Undefined variable: filename (see :help E738)',
\ 'gcc.vim:8:11: error: E128: Function name must start with a capital or contain a colon: foobar (see ynkdir/vim-vimlparser)',
\ 'gcc.vim:9:12: warning: Use robust operators `=~#` or `=~?` instead of `=~` (see Google VimScript Style Guide (Matching))',
\ ]) \ ])