]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/dockerfile/dockerfile_lint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '56df844d3c39ec494dacc69eae34272b27db185a' as '.vim/bundle/asyncomplete'
[etc/vim.git] / .vim / bundle / ale / ale_linters / dockerfile / dockerfile_lint.vim
1 " Author: Alexander Olofsson <alexander.olofsson@liu.se>
2
3 call ale#Set('dockerfile_dockerfile_lint_executable', 'dockerfile_lint')
4 call ale#Set('dockerfile_dockerfile_lint_options', '')
5
6 function! ale_linters#dockerfile#dockerfile_lint#GetType(type) abort
7     if a:type is? 'error'
8         return 'E'
9     elseif a:type is? 'warn'
10         return 'W'
11     endif
12
13     return 'I'
14 endfunction
15
16 function! ale_linters#dockerfile#dockerfile_lint#Handle(buffer, lines) abort
17     try
18         let l:data = json_decode(join(a:lines, ''))
19     catch
20         return []
21     endtry
22
23     if empty(l:data)
24         " Should never happen, but it's better to be on the safe side
25         return []
26     endif
27
28     let l:messages = []
29
30     for l:type in ['error', 'warn', 'info']
31         for l:object in l:data[l:type]['data']
32             let l:line = get(l:object, 'line', -1)
33             let l:message = l:object['message']
34
35             let l:link = get(l:object, 'reference_url', '')
36
37             if type(l:link) == v:t_list
38                 " Somehow, reference_url is returned as two-part list.
39                 " Anchor markers in that list are sometimes duplicated.
40                 " See https://github.com/projectatomic/dockerfile_lint/issues/134
41                 let l:link = join(l:link, '')
42                 let l:link = substitute(l:link, '##', '#', '')
43             endif
44
45             let l:detail = l:message
46
47             if get(l:object, 'description', 'None') isnot# 'None'
48                 let l:detail .= "\n\n" . l:object['description']
49             endif
50
51             let l:detail .= "\n\n" . l:link
52
53             call add(l:messages, {
54             \   'lnum': l:line,
55             \   'text': l:message,
56             \   'type': ale_linters#dockerfile#dockerfile_lint#GetType(l:type),
57             \   'detail': l:detail,
58             \})
59         endfor
60     endfor
61
62     return l:messages
63 endfunction
64
65 function! ale_linters#dockerfile#dockerfile_lint#GetCommand(buffer) abort
66     return '%e' . ale#Pad(ale#Var(a:buffer, 'dockerfile_dockerfile_lint_options'))
67     \   . ' -p -j -f'
68     \   . ' %t'
69 endfunction
70
71 call ale#linter#Define('dockerfile', {
72 \   'name': 'dockerfile_lint',
73 \   'executable': {b -> ale#Var(b, 'dockerfile_dockerfile_lint_executable')},
74 \   'command': function('ale_linters#dockerfile#dockerfile_lint#GetCommand'),
75 \   'callback': 'ale_linters#dockerfile#dockerfile_lint#Handle',
76 \})