From b8359c1114229737563bde4e2478ca2309ce6e7a Mon Sep 17 00:00:00 2001 From: ix5 Date: Thu, 18 Oct 2018 10:19:27 +0200 Subject: [PATCH] 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 --- ale_linters/ansible/ansible_lint.vim | 13 ++++++++++--- doc/ale-ansible.txt | 16 ++++++++++++++++ doc/ale.txt | 2 ++ .../test_ansible_lint_command_callback.vader | 17 +++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 doc/ale-ansible.txt create mode 100644 test/command_callback/test_ansible_lint_command_callback.vader 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 " 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'