From 14265e464af0fde49c4c4751bc2f6a9f7b4812dd Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Mon, 9 May 2022 04:27:21 -0700 Subject: [PATCH] Add support for ansible-lint 6.0.0 (#4189) ansible-lint 6.0.0 removed the `--parseable-severity` option. Use the JSON output in its place. Fixes #4188 --- ale_linters/ansible/ansible_lint.vim | 28 ++++++++++++++++++++++++++-- test/linter/test_ansible_lint.vader | 4 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ale_linters/ansible/ansible_lint.vim b/ale_linters/ansible/ansible_lint.vim index 3b443369..d5d98bc4 100644 --- a/ale_linters/ansible/ansible_lint.vim +++ b/ale_linters/ansible/ansible_lint.vim @@ -18,9 +18,30 @@ function! ale_linters#ansible#ansible_lint#Handle(buffer, version, lines) abort endif endfor - let l:version_group = ale#semver#GTE(a:version, [5, 0, 0]) ? '>=5.0.0' : '<5.0.0' + let l:version_group = ale#semver#GTE(a:version, [6, 0, 0]) ? '>=6.0.0' : + \ ale#semver#GTE(a:version, [5, 0, 0]) ? '>=5.0.0' : + \ '<5.0.0' let l:output = [] + if '>=6.0.0' is# l:version_group + let l:error_codes = { 'blocker': 'E', 'critical': 'E', 'major': 'W', 'minor': 'W', 'info': 'I' } + let l:linter_issues = json_decode(join(a:lines, '')) + + for l:issue in l:linter_issues + if ale#path#IsBufferPath(a:buffer, l:issue.location.path) + call add(l:output, { + \ 'lnum': exists('l:issue.location.lines.begin.column') ? l:issue.location.lines.begin.line : + \ l:issue.location.lines.begin, + \ 'col': exists('l:issue.location.lines.begin.column') ? l:issue.location.lines.begin.column : 0, + \ 'text': l:issue.check_name, + \ 'detail': l:issue.description, + \ 'code': l:issue.severity, + \ 'type': l:error_codes[l:issue.severity], + \}) + endif + endfor + endif + if '>=5.0.0' is# l:version_group " Matches patterns line the following: " test.yml:3:148: syntax-check 'var' is not a valid attribute for a Play @@ -73,10 +94,13 @@ endfunction function! ale_linters#ansible#ansible_lint#GetCommand(buffer, version) abort let l:commands = { + \ '>=6.0.0': '%e --nocolor -f json -x yaml %s', \ '>=5.0.0': '%e --nocolor --parseable-severity -x yaml %s', \ '<5.0.0': '%e --nocolor -p %t' \} - let l:command = ale#semver#GTE(a:version, [5, 0]) ? l:commands['>=5.0.0'] : l:commands['<5.0.0'] + let l:command = ale#semver#GTE(a:version, [6, 0]) ? l:commands['>=6.0.0'] : + \ ale#semver#GTE(a:version, [5, 0]) ? l:commands['>=5.0.0'] : + \ l:commands['<5.0.0'] return l:command endfunction diff --git a/test/linter/test_ansible_lint.vader b/test/linter/test_ansible_lint.vader index 6fb8acb5..3191fa7b 100644 --- a/test/linter/test_ansible_lint.vader +++ b/test/linter/test_ansible_lint.vader @@ -15,6 +15,10 @@ Execute(The ansible_lint version >=5.0.0 command callback should return default GivenCommandOutput ['v5.1.2'] AssertLinter 'ansible-lint', ale#Escape('ansible-lint') . ' --nocolor --parseable-severity -x yaml %s' +Execute(The ansible_lint version >=6.0.0 command callback should return default string): + GivenCommandOutput ['v6.0.2'] + AssertLinter 'ansible-lint', ale#Escape('ansible-lint') . ' --nocolor -f json -x yaml %s' + Execute(The ansible_lint executable should be configurable): let g:ale_ansible_ansible_lint_executable = '~/.local/bin/ansible-lint' GivenCommandOutput ['v4.1.2']