diff options
author | Tim Carry <tim@pixelastic.com> | 2024-01-14 12:51:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-14 20:51:39 +0900 |
commit | 17cca243e33d5c20424373d27fa286b6bdf5a5d6 (patch) | |
tree | 9f1f6604599292fa3a7f6ca71344d566a1a67ffc | |
parent | d63f5e6a77f7883e29ec1cbd8861a87c2fc6fe1a (diff) | |
download | ale-17cca243e33d5c20424373d27fa286b6bdf5a5d6.zip |
Actionlint: correctly parse error line when using shellcheck sublinter (#4689)
-rw-r--r-- | ale_linters/yaml/actionlint.vim | 18 | ||||
-rw-r--r-- | test/linter/test_yaml_actionlint.vader | 20 |
2 files changed, 32 insertions, 6 deletions
diff --git a/ale_linters/yaml/actionlint.vim b/ale_linters/yaml/actionlint.vim index 75fe3162..0984defb 100644 --- a/ale_linters/yaml/actionlint.vim +++ b/ale_linters/yaml/actionlint.vim @@ -21,15 +21,27 @@ endfunction function! ale_linters#yaml#actionlint#Handle(buffer, lines) abort " Matches patterns line the following: ".github/workflows/main.yml:19:0: could not parse as YAML: yaml: line 19: mapping values are not allowed in this context [yaml-syntax] - let l:pattern = '\v^.*:(\d+):(\d+): (.+) \[(.+)\]$' + let l:pattern = '\v^.{-}:(\d+):(\d+): (.+) \[(.+)\]$' let l:output = [] + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:code = l:match[4] + let l:text = l:match[3] + + " Handle sub-linter errors like the following: + "validate.yml:19:9: shellcheck reported issue in this script: SC2086:info:1:15: Double quote to prevent globbing and word splitting [shellcheck] + if l:code is# 'shellcheck' + let l:shellcheck_match = matchlist(l:text, '\v^.+: (SC\d{4}):.+:\d+:\d+: (.+)$') + let l:text = l:shellcheck_match[2] + let l:code = 'shellcheck ' . l:shellcheck_match[1] + endif + let l:item = { \ 'lnum': l:match[1] + 0, \ 'col': l:match[2] + 0, - \ 'text': l:match[3], - \ 'code': l:match[4], + \ 'text': l:text, + \ 'code': l:code, \ 'type': 'E', \} diff --git a/test/linter/test_yaml_actionlint.vader b/test/linter/test_yaml_actionlint.vader index 82ab2f6d..707f9cae 100644 --- a/test/linter/test_yaml_actionlint.vader +++ b/test/linter/test_yaml_actionlint.vader @@ -1,9 +1,8 @@ Before: - runtime! ale/handlers/actionlint.vim + call ale#assert#SetUpLinterTest('yaml', 'actionlint') After: - unlet! g:ale_yaml_actionlint_options - call ale#linter#Reset() + call ale#assert#TearDownLinterTest() Execute(Problems should be parsed correctly for actionlint): AssertEqual @@ -28,6 +27,21 @@ Execute(Problems should be parsed correctly for actionlint): \ 'workflow_call_event.yaml:56:23: property "unknown_input" is not defined in object type {input7: bool; input0: any; input1: any; input2: string; input3: any; input4: any; input5: number; input6: number} [expression]', \ ]) +Execute(Shellcheck issues should be reported at the line they appear): + AssertEqual + \ [ + \ { + \ 'lnum': 19, + \ 'col': 9, + \ 'type': 'E', + \ 'text': 'Double quote to prevent globbing and word splitting', + \ 'code': 'shellcheck SC2086', + \ }, + \ ], + \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ + \ 'validate.yml:19:9: shellcheck reported issue in this script: SC2086:info:1:15: Double quote to prevent globbing and word splitting [shellcheck]' + \ ]) + Execute(Command should always have -no-color and -oneline options): let g:ale_yaml_actionlint_options = '' |