All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Peter Benjamin <petermbenjamin@gmail.com>
2 " Description: Linter for GitHub Workflows
4 call ale#Set('yaml_actionlint_executable', 'actionlint')
5 call ale#Set('yaml_actionlint_options', '')
7 function! ale_linters#yaml#actionlint#GetCommand(buffer) abort
8 " Only execute actionlint on YAML files in /.github/ paths.
9 if expand('#' . a:buffer . ':p') !~# '\v[/\\]\.github[/\\]'
13 let l:options = ale#Var(a:buffer, 'yaml_actionlint_options')
15 if l:options !~# '-no-color'
16 let l:options .= ale#Pad('-no-color')
19 if l:options !~# '-oneline'
20 let l:options .= ale#Pad('-oneline')
23 let l:configfile = ale_linters#yaml#actionlint#GitRepoHasConfig(a:buffer)
25 if !empty(l:configfile)
26 let l:options .= ale#Pad('-config-file ' . l:configfile)
29 return '%e' . ale#Pad(l:options) . ' - '
32 " If we have a actionlint.yml or actionlint.yaml in our github directory
33 " use that as our config file.
34 function! ale_linters#yaml#actionlint#GitRepoHasConfig(buffer) abort
35 let l:filename = expand('#' . a:buffer . ':p')
36 let l:configfilebase = substitute(l:filename, '\.github/.*', '.github/actionlint.','')
38 for l:ext in ['yml', 'yaml']
39 let l:configfile = l:configfilebase . l:ext
41 if filereadable(l:configfile)
49 function! ale_linters#yaml#actionlint#Handle(buffer, lines) abort
50 " Matches patterns line the following:
51 ".github/workflows/main.yml:19:0: could not parse as YAML: yaml: line 19: mapping values are not allowed in this context [yaml-syntax]
52 let l:pattern = '\v^.{-}:(\d+):(\d+): (.+) \[(.+)\]$'
56 for l:match in ale#util#GetMatches(a:lines, l:pattern)
57 let l:code = l:match[4]
58 let l:text = l:match[3]
60 " Handle sub-linter errors like the following:
61 "validate.yml:19:9: shellcheck reported issue in this script: SC2086:info:1:15: Double quote to prevent globbing and word splitting [shellcheck]
62 if l:code is# 'shellcheck'
63 let l:shellcheck_match = matchlist(l:text, '\v^.+: (SC\d{4}):.+:\d+:\d+: (.+)$')
64 let l:text = l:shellcheck_match[2]
65 let l:code = 'shellcheck ' . l:shellcheck_match[1]
69 \ 'lnum': l:match[1] + 0,
70 \ 'col': l:match[2] + 0,
76 call add(l:output, l:item)
82 call ale#linter#Define('yaml', {
83 \ 'name': 'actionlint',
84 \ 'executable': {b -> ale#Var(b, 'yaml_actionlint_executable')},
85 \ 'command': function('ale_linters#yaml#actionlint#GetCommand'),
86 \ 'callback': 'ale_linters#yaml#actionlint#Handle',