Fix #216 - Filter out errors for other files for ansible-lint

This commit is contained in:
w0rp 2017-07-03 23:16:39 +01:00
parent a1cf7f67a1
commit bb293b297c
2 changed files with 24 additions and 15 deletions

View File

@ -15,11 +15,11 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
" Matches patterns line the following: " Matches patterns line the following:
" "
" test.yml:35: [EANSIBLE0002] Trailing whitespace " test.yml:35: [EANSIBLE0002] Trailing whitespace
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: \[?([[:alnum:]]+)\]? (.*)$' let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?: \[?([[:alnum:]]+)\]? (.*)$'
let l:output = [] let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern) for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:code = l:match[3] let l:code = l:match[4]
if (l:code ==# 'EANSIBLE002') if (l:code ==# 'EANSIBLE002')
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace') \ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
@ -27,14 +27,14 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
continue continue
endif endif
let l:item = { if ale#path#IsBufferPath(a:buffer, l:match[1])
\ 'lnum': l:match[1] + 0, call add(l:output, {
\ 'col': l:match[2] + 0, \ 'lnum': l:match[2] + 0,
\ 'text': l:code . ': ' . l:match[4], \ 'col': l:match[3] + 0,
\ 'type': l:code[:0] ==# 'E' ? 'E' : 'W', \ 'text': l:code . ': ' . l:match[5],
\} \ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
\})
call add(l:output, l:item) endif
endfor endfor
return l:output return l:output

View File

@ -1,5 +1,6 @@
Before: Before:
runtime ale_linters/ansible/ansible_lint.vim runtime ale_linters/ansible/ansible_lint.vim
call ale#test#SetFilename('main.yml')
After: After:
call ale#linter#Reset() call ale#linter#Reset()
@ -11,11 +12,11 @@ Execute(The ansible-lint handler should handle basic errors):
\ 'lnum': 35, \ 'lnum': 35,
\ 'col': 0, \ 'col': 0,
\ 'type': 'E', \ 'type': 'E',
\ 'text': "EANSIBLE0002: Trailing whitespace", \ 'text': 'EANSIBLE0002: Trailing whitespace',
\ }, \ },
\ ], \ ],
\ ale_linters#ansible#ansible_lint#Handle(42, [ \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [
\ "test.yml:35: [EANSIBLE0002] Trailing whitespace", \ '/tmp/vxepmGL/1/main.yml:35: [EANSIBLE0002] Trailing whitespace',
\ ]) \ ])
Execute (The ansible-lint handler should handle names with spaces): Execute (The ansible-lint handler should handle names with spaces):
@ -28,6 +29,14 @@ Execute (The ansible-lint handler should handle names with spaces):
\ 'text': 'E111: indentation is not a multiple of four', \ 'text': 'E111: indentation is not a multiple of four',
\ }, \ },
\ ], \ ],
\ ale_linters#ansible#ansible_lint#Handle(42, [ \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [
\ 'C:\something\with spaces.yml:6:6: E111 indentation is not a multiple of four', \ '/tmp/vxepm GL/1/main.yml:6:6: E111 indentation is not a multiple of four',
\ ])
Execute (The ansible-lint handler should ignore errors from other files):
AssertEqual
\ [
\ ],
\ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [
\ '/foo/bar/roles/main.yml:6:6: E111 indentation is not a multiple of four',
\ ]) \ ])