Skip to content

Commit

Permalink
add yaml actionlint support (github actions) (dense-analysis#4173)
Browse files Browse the repository at this point in the history
Co-authored-by: bretello <bretello@distruzione.org>
  • Loading branch information
2 people authored and cyyever committed Jul 11, 2022
1 parent 77b5795 commit 3dc2986
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ale_linters/yaml/actionlint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" Author: bretello <bretello@distruzione.org>

call ale#Set('yaml_actionlint_executable', 'actionlint')

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',
\})
24 changes: 24 additions & 0 deletions autoload/ale/handlers/actionlint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function! ale#handlers#actionlint#GetCommand(buffer) abort
return '%e --no-color --oneline %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
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ Notes:
* XML
* `xmllint`
* YAML
* `actionlint`
* `circleci`!!
* `prettier`
* `spectral`
Expand Down
22 changes: 22 additions & 0 deletions doc/ale-yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
ALE YAML Integration *ale-yaml-options*


===============================================================================
actionlint *ale-yaml-actionlint*

Website: https://github.com/rhysd/actionlint


Installation
-------------------------------------------------------------------------------

See installation guide: https://github.com/rhysd/actionlint#quick-start

Options
-------------------------------------------------------------------------------

g:ale_yaml_actionlint_executable *g:ale_yaml_actionlint_executable*
*b:ale_yaml_actionlint_executable*
Type: |String|
Default: `'actionlint'`

This variable can be set to change the path to actionlint.


===============================================================================
circleci *ale-yaml-circleci*

Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3272,6 +3272,7 @@ documented in additional help files.
xml.....................................|ale-xml-options|
xmllint...............................|ale-xml-xmllint|
yaml....................................|ale-yaml-options|
actionlint............................|ale-yaml-actionlint|
circleci..............................|ale-yaml-circleci|
prettier..............................|ale-yaml-prettier|
spectral..............................|ale-yaml-spectral|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ formatting.
* XML
* [xmllint](http://xmlsoft.org/xmllint.html)
* YAML
* [actionlint](https://github.com/rhysd/actionlint)
* [circleci](https://circleci.com/docs/2.0/local-cli) :floppy_disk:
* [prettier](https://github.com/prettier/prettier)
* [spectral](https://github.com/stoplightio/spectral)
Expand Down
28 changes: 28 additions & 0 deletions test/handler/test_actionlint_handler.vader
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Before:
runtime! ale/handlers/actionlint.vim

After:
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]',
\ ])

0 comments on commit 3dc2986

Please sign in to comment.