summaryrefslogtreecommitdiff
path: root/ale_linters/dockerfile/dockerfile_lint.vim
blob: a5a846f239544103f84ee96c54832c089c3c900e (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
50
51
52
53
54
55
56
57
58
59
60
61
" Author: Alexander Olofsson <alexander.olofsson@liu.se>

call ale#Set('dockerfile_dockerfile_lint_executable', 'dockerfile_lint')
call ale#Set('dockerfile_dockerfile_lint_options', '')

function! ale_linters#dockerfile#dockerfile_lint#GetType(type) abort
    if a:type is? 'error'
        return 'E'
    elseif a:type is? 'warn'
        return 'W'
    endif

    return 'I'
endfunction

function! ale_linters#dockerfile#dockerfile_lint#Handle(buffer, lines) abort
    try
        let l:data = json_decode(join(a:lines, ''))
    catch
        return []
    endtry

    if empty(l:data)
        " Should never happen, but it's better to be on the safe side
        return []
    endif

    let l:messages = []

    for l:type in ['error', 'warn', 'info']
        for l:object in l:data[l:type]['data']
            let l:line = get(l:object, 'line', -1)
            let l:message = l:object['message']

            if get(l:object, 'description', 'None') isnot# 'None'
                let l:message = l:message . '. ' . l:object['description']
            endif

            call add(l:messages, {
            \   'lnum': l:line,
            \   'text': l:message,
            \   'type': ale_linters#dockerfile#dockerfile_lint#GetType(l:type),
            \})
        endfor
    endfor

    return l:messages
endfunction

function! ale_linters#dockerfile#dockerfile_lint#GetCommand(buffer) abort
    return '%e' . ale#Pad(ale#Var(a:buffer, 'dockerfile_dockerfile_lint_options'))
    \   . ' -p -j -f'
    \   . ' %t'
endfunction

call ale#linter#Define('dockerfile', {
\   'name': 'dockerfile_lint',
\   'executable_callback': ale#VarFunc('dockerfile_dockerfile_lint_executable'),
\   'command_callback': 'ale_linters#dockerfile#dockerfile_lint#GetCommand',
\   'callback': 'ale_linters#dockerfile#dockerfile_lint#Handle',
\})