Allow custom executable for ansible linters (#1977)
* Allow custom executable for ansible linters * Add ansible-lint tests * ansible-lint: simplify linter command * Rename linter "ansible" to "ansible_lint" * Add ansible-lint options to documentation * Add alias ansible-lint for ansible_lint
This commit is contained in:
parent
3b38a83ae9
commit
b8359c1114
4 changed files with 45 additions and 3 deletions
|
@ -1,6 +1,12 @@
|
||||||
" Author: Bjorn Neergaard <bjorn@neersighted.com>
|
" Author: Bjorn Neergaard <bjorn@neersighted.com>
|
||||||
" Description: ansible-lint for ansible-yaml files
|
" Description: ansible-lint for ansible-yaml files
|
||||||
|
|
||||||
|
call ale#Set('ansible_ansible_lint_executable', 'ansible-lint')
|
||||||
|
|
||||||
|
function! ale_linters#ansible#ansible_lint#GetExecutable(buffer) abort
|
||||||
|
return ale#Var(a:buffer, 'ansible_ansible_lint_executable')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
|
function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
|
||||||
for l:line in a:lines[:10]
|
for l:line in a:lines[:10]
|
||||||
if match(l:line, '^Traceback') >= 0
|
if match(l:line, '^Traceback') >= 0
|
||||||
|
@ -42,8 +48,9 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('ansible', {
|
call ale#linter#Define('ansible', {
|
||||||
\ 'name': 'ansible',
|
\ 'name': 'ansible_lint',
|
||||||
\ 'executable': 'ansible',
|
\ 'aliases': ['ansible', 'ansible-lint'],
|
||||||
\ 'command': 'ansible-lint -p %t',
|
\ 'executable_callback': 'ale_linters#ansible#ansible_lint#GetExecutable',
|
||||||
|
\ 'command': '%e -p %t',
|
||||||
\ 'callback': 'ale_linters#ansible#ansible_lint#Handle',
|
\ 'callback': 'ale_linters#ansible#ansible_lint#Handle',
|
||||||
\})
|
\})
|
||||||
|
|
16
doc/ale-ansible.txt
Normal file
16
doc/ale-ansible.txt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
===============================================================================
|
||||||
|
ALE Ansible Integration *ale-ansible-options*
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
ansible-lint *ale-ansible-ansible-lint*
|
||||||
|
|
||||||
|
g:ale_ansible_ansible_lint_executable *g:ale_ansible_ansible_lint_executable*
|
||||||
|
*b:ale_ansible_ansible_lint_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'ansible-lint'`
|
||||||
|
|
||||||
|
This variable can be changed to modify the executable used for ansible-lint.
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
|
@ -18,6 +18,8 @@ CONTENTS *ale-contents*
|
||||||
6.1 Highlights........................|ale-highlights|
|
6.1 Highlights........................|ale-highlights|
|
||||||
6.2 Options for write-good Linter.....|ale-write-good-options|
|
6.2 Options for write-good Linter.....|ale-write-good-options|
|
||||||
7. Integration Documentation............|ale-integrations|
|
7. Integration Documentation............|ale-integrations|
|
||||||
|
ansible...............................|ale-ansible-options|
|
||||||
|
ansible-lint........................|ale-ansible-ansible-lint|
|
||||||
asciidoc..............................|ale-asciidoc-options|
|
asciidoc..............................|ale-asciidoc-options|
|
||||||
write-good..........................|ale-asciidoc-write-good|
|
write-good..........................|ale-asciidoc-write-good|
|
||||||
asm...................................|ale-asm-options|
|
asm...................................|ale-asm-options|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('ansible', 'ansible_lint')
|
||||||
|
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet! b:bin_dir
|
||||||
|
unlet! b:executable
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The ansible_lint command callback should return default string):
|
||||||
|
AssertLinter 'ansible-lint', ale#Escape('ansible-lint') . ' -p %t'
|
||||||
|
|
||||||
|
Execute(The ansible_lint executable should be configurable):
|
||||||
|
let g:ale_ansible_ansible_lint_executable = '~/.local/bin/ansible-lint'
|
||||||
|
|
||||||
|
AssertLinter '~/.local/bin/ansible-lint',
|
||||||
|
\ ale#Escape('~/.local/bin/ansible-lint') . ' -p %t'
|
Reference in a new issue