2017-06-14 15:20:30 +00:00
|
|
|
" Author: Bjorn Neergaard <bjorn@neersighted.com>
|
|
|
|
" Description: ansible-lint for ansible-yaml files
|
|
|
|
|
|
|
|
function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
|
|
|
|
for l:line in a:lines[:10]
|
|
|
|
if match(l:line, '^Traceback') >= 0
|
|
|
|
return [{
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'text': 'An exception was thrown. See :ALEDetail',
|
|
|
|
\ 'detail': join(a:lines, "\n"),
|
|
|
|
\}]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Matches patterns line the following:
|
|
|
|
"
|
|
|
|
" test.yml:35: [EANSIBLE0002] Trailing whitespace
|
2017-07-03 22:16:39 +00:00
|
|
|
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?: \[?([[:alnum:]]+)\]? (.*)$'
|
2017-06-14 15:20:30 +00:00
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-07-03 22:16:39 +00:00
|
|
|
let l:code = l:match[4]
|
2017-06-14 15:20:30 +00:00
|
|
|
|
2017-12-13 11:14:31 +00:00
|
|
|
if l:code is# 'EANSIBLE0002'
|
2017-08-08 07:39:13 +00:00
|
|
|
\&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
|
2017-06-14 15:20:30 +00:00
|
|
|
" Skip warnings for trailing whitespace if the option is off.
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2017-07-03 22:16:39 +00:00
|
|
|
if ale#path#IsBufferPath(a:buffer, l:match[1])
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
2017-11-15 10:11:32 +00:00
|
|
|
\ 'text': l:match[5],
|
|
|
|
\ 'code': l:code,
|
2017-08-08 07:39:13 +00:00
|
|
|
\ 'type': l:code[:0] is# 'E' ? 'E' : 'W',
|
2017-07-03 22:16:39 +00:00
|
|
|
\})
|
|
|
|
endif
|
2017-06-14 15:20:30 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('ansible', {
|
|
|
|
\ 'name': 'ansible',
|
|
|
|
\ 'executable': 'ansible',
|
|
|
|
\ 'command': 'ansible-lint -p %t',
|
|
|
|
\ 'callback': 'ale_linters#ansible#ansible_lint#Handle',
|
|
|
|
\})
|