summaryrefslogtreecommitdiff
path: root/ale_linters/yaml/gitlablint.vim
blob: ec48115af0d0b4605cbe5ae8abc848e6a7db1d4e (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
48
49
call ale#Set('yaml_gitlablint_executable', 'gll')
call ale#Set('yaml_gitlablint_options', '')

function! ale_linters#yaml#gitlablint#GetCommand(buffer) abort
    return '%e' . ale#Pad(ale#Var(a:buffer, 'yaml_gitlablint_options'))
    \   . ' -p %t'
endfunction

function! ale_linters#yaml#gitlablint#Handle(buffer, lines) abort
    " Matches patterns line the following:
    " (<unknown>): mapping values are not allowed in this context at line 68 column 8
    " jobs:build:dev config contains unknown keys: ony
    let l:pattern = '^\(.*\) at line \(\d\+\) column \(\d\+\)$'
    let l:output = []

    for l:line in a:lines
        let l:match = matchlist(l:line, l:pattern)

        if !empty(l:match)
            let l:item = {
            \   'lnum': l:match[2] + 0,
            \   'col': l:match[3] + 0,
            \   'text': l:match[1],
            \   'type': 'E',
            \}
            call add(l:output, l:item)
        else
            if l:line isnot# 'GitLab CI configuration is invalid'
                let l:item = {
                \   'lnum': 0,
                \   'col': 0,
                \   'text': l:line,
                \   'type': 'E',
                \}
                call add(l:output, l:item)
            endif
        endif
    endfor

    return l:output
endfunction

call ale#linter#Define('yaml', {
\   'name': 'gitlablint',
\   'executable': {b -> ale#Var(b, 'yaml_gitlablint_executable')},
\   'command': function('ale_linters#yaml#gitlablint#GetCommand'),
\   'callback': 'ale_linters#yaml#gitlablint#Handle',
\   'output_stream': 'stderr',
\})