1
0
Fork 0
mirror of synced 2024-10-18 09:49:00 -04:00
ultimate-vim/sources_non_forked/ale/ale_linters/yaml/actionlint.vim

65 lines
2.1 KiB
VimL
Raw Normal View History

2024-01-07 10:14:20 -05:00
" Author: Peter Benjamin <petermbenjamin@gmail.com>
" Description: Linter for GitHub Workflows
2022-08-08 09:45:34 -04:00
call ale#Set('yaml_actionlint_executable', 'actionlint')
call ale#Set('yaml_actionlint_options', '')
2024-01-07 10:14:20 -05:00
function! ale_linters#yaml#actionlint#GetCommand(buffer) abort
2024-10-06 04:25:50 -04:00
" Only execute actionlint on YAML files in /.github/ paths.
if expand('#' . a:buffer . ':p') !~# '\v[/\\]\.github[/\\]'
return ''
endif
2024-01-07 10:14:20 -05:00
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
2024-10-06 04:25:50 -04:00
return '%e' . ale#Pad(l:options) . ' - '
2024-01-07 10:14:20 -05:00
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]
2024-10-06 04:25:50 -04:00
let l:pattern = '\v^.{-}:(\d+):(\d+): (.+) \[(.+)\]$'
2024-01-07 10:14:20 -05:00
let l:output = []
2024-10-06 04:25:50 -04:00
2024-01-07 10:14:20 -05:00
for l:match in ale#util#GetMatches(a:lines, l:pattern)
2024-10-06 04:25:50 -04:00
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
2024-01-07 10:14:20 -05:00
let l:item = {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
2024-10-06 04:25:50 -04:00
\ 'text': l:text,
\ 'code': l:code,
2024-01-07 10:14:20 -05:00
\ 'type': 'E',
\}
call add(l:output, l:item)
endfor
return l:output
endfunction
2022-08-08 09:45:34 -04:00
call ale#linter#Define('yaml', {
\ 'name': 'actionlint',
\ 'executable': {b -> ale#Var(b, 'yaml_actionlint_executable')},
2024-01-07 10:14:20 -05:00
\ 'command': function('ale_linters#yaml#actionlint#GetCommand'),
\ 'callback': 'ale_linters#yaml#actionlint#Handle',
2022-08-08 09:45:34 -04:00
\})