From 3bedafc29a45d478f41d8467a988e29c35618737 Mon Sep 17 00:00:00 2001 From: Peter Benjamin Date: Tue, 5 Sep 2023 06:33:41 -0700 Subject: fix(yaml): make actionlint respect config (#4584) * fix(yaml): make actionlint respect config * docs: update actionlint docs * chore: update author & add description * test: move actionlint test to test/linter/ --- ale_linters/yaml/actionlint.vim | 42 ++++++++++++++++++++++++++--- autoload/ale/handlers/actionlint.vim | 36 ------------------------- test/handler/test_actionlint_handler.vader | 43 ------------------------------ test/linter/test_yaml_actionlint.vader | 43 ++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 autoload/ale/handlers/actionlint.vim delete mode 100644 test/handler/test_actionlint_handler.vader create mode 100644 test/linter/test_yaml_actionlint.vader diff --git a/ale_linters/yaml/actionlint.vim b/ale_linters/yaml/actionlint.vim index 1e2fda49..75fe3162 100644 --- a/ale_linters/yaml/actionlint.vim +++ b/ale_linters/yaml/actionlint.vim @@ -1,11 +1,47 @@ -" Author: bretello +" Author: Peter Benjamin +" Description: Linter for GitHub Workflows call ale#Set('yaml_actionlint_executable', 'actionlint') call ale#Set('yaml_actionlint_options', '') +function! ale_linters#yaml#actionlint#GetCommand(buffer) abort + let l:options = ale#Var(a:buffer, 'yaml_actionlint_options') + + if l:options !~# '-no-color' + let l:options .= ale#Pad('-no-color') + endif + + if l:options !~# '-oneline' + let l:options .= ale#Pad('-oneline') + endif + + return '%e' . ale#Pad(l:options) +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:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + let l:item = { + \ 'lnum': l:match[1] + 0, + \ 'col': l:match[2] + 0, + \ 'text': l:match[3], + \ 'code': l:match[4], + \ 'type': 'E', + \} + + call add(l:output, l:item) + endfor + + return l:output +endfunction + call ale#linter#Define('yaml', { \ 'name': 'actionlint', \ 'executable': {b -> ale#Var(b, 'yaml_actionlint_executable')}, -\ 'command': function('ale#handlers#actionlint#GetCommand'), -\ 'callback': 'ale#handlers#actionlint#Handle', +\ 'command': function('ale_linters#yaml#actionlint#GetCommand'), +\ 'callback': 'ale_linters#yaml#actionlint#Handle', \}) diff --git a/autoload/ale/handlers/actionlint.vim b/autoload/ale/handlers/actionlint.vim deleted file mode 100644 index 73843c08..00000000 --- a/autoload/ale/handlers/actionlint.vim +++ /dev/null @@ -1,36 +0,0 @@ -function! ale#handlers#actionlint#GetCommand(buffer) abort - let l:options = ale#Var(a:buffer, 'yaml_actionlint_options') - - " automatically add --no-color option if not defined - if l:options !~# '--no-color' - let l:options .= ' --no-color' - endif - - " automatically add --oneline option if not defined - if l:options !~# '--oneline' - let l:options .= ' --oneline' - endif - - return '%e ' . l:options . ' %t' -endfunction - -function! ale#handlers#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:output = [] - - for l:match in ale#util#GetMatches(a:lines, l:pattern) - let l:item = { - \ 'lnum': l:match[1] + 0, - \ 'col': l:match[2] + 0, - \ 'text': l:match[3], - \ 'code': l:match[4], - \ 'type': 'E', - \} - - call add(l:output, l:item) - endfor - - return l:output -endfunction diff --git a/test/handler/test_actionlint_handler.vader b/test/handler/test_actionlint_handler.vader deleted file mode 100644 index 3e762129..00000000 --- a/test/handler/test_actionlint_handler.vader +++ /dev/null @@ -1,43 +0,0 @@ -Before: - runtime! ale/handlers/actionlint.vim - -After: - unlet! g:ale_yaml_actionlint_options - call ale#linter#Reset() - -Execute(Problems should be parsed correctly for actionlint): - AssertEqual - \ [ - \ { - \ 'lnum': 2, - \ 'col': 1, - \ 'type': 'E', - \ 'text': '"jobs" section is missing in workflow', - \ 'code': 'syntax-check', - \ }, - \ { - \ 'lnum': 56, - \ 'col': 23, - \ 'type': 'E', - \ 'text': '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}', - \ 'code': 'expression', - \ }, - \ ], - \ ale#handlers#actionlint#Handle(bufnr(''), [ - \ '.codecov.yaml:2:1: "jobs" section is missing in workflow [syntax-check]', - \ '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(Command should always have --no-color and --oneline options): - let g:ale_yaml_actionlint_options = '' - - AssertEqual - \ '%e --no-color --oneline %t', - \ ale#handlers#actionlint#GetCommand(bufnr('')) - -Execute(Options should be added to command): - let g:ale_yaml_actionlint_options = '-shellcheck= -pyflakes=' - - AssertEqual - \ '%e -shellcheck= -pyflakes= --no-color --oneline %t', - \ ale#handlers#actionlint#GetCommand(bufnr('')) diff --git a/test/linter/test_yaml_actionlint.vader b/test/linter/test_yaml_actionlint.vader new file mode 100644 index 00000000..82ab2f6d --- /dev/null +++ b/test/linter/test_yaml_actionlint.vader @@ -0,0 +1,43 @@ +Before: + runtime! ale/handlers/actionlint.vim + +After: + unlet! g:ale_yaml_actionlint_options + call ale#linter#Reset() + +Execute(Problems should be parsed correctly for actionlint): + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 1, + \ 'type': 'E', + \ 'text': '"jobs" section is missing in workflow', + \ 'code': 'syntax-check', + \ }, + \ { + \ 'lnum': 56, + \ 'col': 23, + \ 'type': 'E', + \ 'text': '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}', + \ 'code': 'expression', + \ }, + \ ], + \ ale_linters#yaml#actionlint#Handle(bufnr(''), [ + \ '.codecov.yaml:2:1: "jobs" section is missing in workflow [syntax-check]', + \ '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(Command should always have -no-color and -oneline options): + let g:ale_yaml_actionlint_options = '' + + AssertEqual + \ '%e -no-color -oneline', + \ ale_linters#yaml#actionlint#GetCommand(bufnr('')) + +Execute(Options should be added to command): + let g:ale_yaml_actionlint_options = '-shellcheck= -pyflakes=' + + AssertEqual + \ '%e -shellcheck= -pyflakes= -no-color -oneline', + \ ale_linters#yaml#actionlint#GetCommand(bufnr('')) -- cgit v1.2.3