summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-07-03 23:16:39 +0100
committerw0rp <devw0rp@gmail.com>2017-07-03 23:18:49 +0100
commit0819c4cd561238e85d8d401bd9b57f51d9932a30 (patch)
tree4f8e0757ed33ced9b372411087efc7ab6ab250b7
parent448600fe4fa5b011132b5c4484a854d5ea00bf3d (diff)
downloadale-0819c4cd561238e85d8d401bd9b57f51d9932a30.zip
Fix #216 - Filter out errors for other files for ansible-lint
-rw-r--r--ale_linters/ansible/ansible_lint.vim20
-rw-r--r--test/handler/test_ansible_lint_handler.vader19
2 files changed, 24 insertions, 15 deletions
diff --git a/ale_linters/ansible/ansible_lint.vim b/ale_linters/ansible/ansible_lint.vim
index 3efd95fd..192e65b9 100644
--- a/ale_linters/ansible/ansible_lint.vim
+++ b/ale_linters/ansible/ansible_lint.vim
@@ -15,11 +15,11 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
" Matches patterns line the following:
"
" 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 = []
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')
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
@@ -27,14 +27,14 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
continue
endif
- let l:item = {
- \ 'lnum': l:match[1] + 0,
- \ 'col': l:match[2] + 0,
- \ 'text': l:code . ': ' . l:match[4],
- \ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
- \}
-
- call add(l:output, l:item)
+ if ale#path#IsBufferPath(a:buffer, l:match[1])
+ call add(l:output, {
+ \ 'lnum': l:match[2] + 0,
+ \ 'col': l:match[3] + 0,
+ \ 'text': l:code . ': ' . l:match[5],
+ \ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
+ \})
+ endif
endfor
return l:output
diff --git a/test/handler/test_ansible_lint_handler.vader b/test/handler/test_ansible_lint_handler.vader
index cffe29fd..b14b1f63 100644
--- a/test/handler/test_ansible_lint_handler.vader
+++ b/test/handler/test_ansible_lint_handler.vader
@@ -1,5 +1,6 @@
Before:
runtime ale_linters/ansible/ansible_lint.vim
+ call ale#test#SetFilename('main.yml')
After:
call ale#linter#Reset()
@@ -11,11 +12,11 @@ Execute(The ansible-lint handler should handle basic errors):
\ 'lnum': 35,
\ 'col': 0,
\ 'type': 'E',
- \ 'text': "EANSIBLE0002: Trailing whitespace",
+ \ 'text': 'EANSIBLE0002: Trailing whitespace',
\ },
\ ],
- \ ale_linters#ansible#ansible_lint#Handle(42, [
- \ "test.yml:35: [EANSIBLE0002] Trailing whitespace",
+ \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [
+ \ '/tmp/vxepmGL/1/main.yml:35: [EANSIBLE0002] Trailing whitespace',
\ ])
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',
\ },
\ ],
- \ ale_linters#ansible#ansible_lint#Handle(42, [
- \ 'C:\something\with spaces.yml:6:6: E111 indentation is not a multiple of four',
+ \ ale_linters#ansible#ansible_lint#Handle(bufnr(''), [
+ \ '/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',
\ ])