summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorix5 <ix5@users.noreply.github.com>2018-10-18 10:19:27 +0200
committerw0rp <w0rp@users.noreply.github.com>2018-10-18 09:19:27 +0100
commitb8359c1114229737563bde4e2478ca2309ce6e7a (patch)
tree8a1c4ec9f95f259872143d449440d93222797f8f
parent3b38a83ae9c221e0f4589f087bfb6b43056e3943 (diff)
downloadale-b8359c1114229737563bde4e2478ca2309ce6e7a.zip
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
-rw-r--r--ale_linters/ansible/ansible_lint.vim13
-rw-r--r--doc/ale-ansible.txt16
-rw-r--r--doc/ale.txt2
-rw-r--r--test/command_callback/test_ansible_lint_command_callback.vader17
4 files changed, 45 insertions, 3 deletions
diff --git a/ale_linters/ansible/ansible_lint.vim b/ale_linters/ansible/ansible_lint.vim
index 0b3b39c8..99fff6c3 100644
--- a/ale_linters/ansible/ansible_lint.vim
+++ b/ale_linters/ansible/ansible_lint.vim
@@ -1,6 +1,12 @@
" Author: Bjorn Neergaard <bjorn@neersighted.com>
" 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
for l:line in a:lines[:10]
if match(l:line, '^Traceback') >= 0
@@ -42,8 +48,9 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, lines) abort
endfunction
call ale#linter#Define('ansible', {
-\ 'name': 'ansible',
-\ 'executable': 'ansible',
-\ 'command': 'ansible-lint -p %t',
+\ 'name': 'ansible_lint',
+\ 'aliases': ['ansible', 'ansible-lint'],
+\ 'executable_callback': 'ale_linters#ansible#ansible_lint#GetExecutable',
+\ 'command': '%e -p %t',
\ 'callback': 'ale_linters#ansible#ansible_lint#Handle',
\})
diff --git a/doc/ale-ansible.txt b/doc/ale-ansible.txt
new file mode 100644
index 00000000..3a4efaa5
--- /dev/null
+++ b/doc/ale-ansible.txt
@@ -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:
diff --git a/doc/ale.txt b/doc/ale.txt
index ffaffbbf..3aab94b4 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -18,6 +18,8 @@ CONTENTS *ale-contents*
6.1 Highlights........................|ale-highlights|
6.2 Options for write-good Linter.....|ale-write-good-options|
7. Integration Documentation............|ale-integrations|
+ ansible...............................|ale-ansible-options|
+ ansible-lint........................|ale-ansible-ansible-lint|
asciidoc..............................|ale-asciidoc-options|
write-good..........................|ale-asciidoc-write-good|
asm...................................|ale-asm-options|
diff --git a/test/command_callback/test_ansible_lint_command_callback.vader b/test/command_callback/test_ansible_lint_command_callback.vader
new file mode 100644
index 00000000..ddc6c6c8
--- /dev/null
+++ b/test/command_callback/test_ansible_lint_command_callback.vader
@@ -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'