summaryrefslogtreecommitdiff
path: root/ale_linters/yaml/actionlint.vim
blob: 75fe3162412f97f1279d7ffd6c676776fc920df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
" Author: Peter Benjamin <petermbenjamin@gmail.com>
" 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_linters#yaml#actionlint#GetCommand'),
\   'callback': 'ale_linters#yaml#actionlint#Handle',
\})