]> git.madduck.net Git - etc/vim.git/blob - ale_linters/dockerfile/dockerlinter.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / dockerfile / dockerlinter.vim
1 " Author: Shad
2 " Description: dockerlinter linter for dockerfile
3
4 call ale#Set('dockerfile_dockerlinter_executable', 'dockerlinter')
5 call ale#Set('dockerfile_dockerlinter_options', '')
6
7 function! ale_linters#dockerfile#dockerlinter#GetType(type) abort
8     if a:type is? 'error'
9         return 'E'
10     elseif a:type is? 'warning'
11         return 'W'
12     endif
13
14     return 'I'
15 endfunction
16
17 function! ale_linters#dockerfile#dockerlinter#Handle(buffer, lines) abort
18     try
19         let l:data = json_decode(join(a:lines, ''))
20     catch
21         return []
22     endtry
23
24     if empty(l:data)
25         " Should never happen, but it's better to be on the safe side
26         return []
27     endif
28
29     let l:messages = []
30
31     for l:object in l:data
32         let l:line = get(l:object, 'lineNumber', -1)
33         let l:message = l:object['message']
34         let l:type = l:object['level']
35         let l:detail = l:message
36         let l:code = l:object['code']
37
38         if l:code =~# '^SC'
39             let l:link = 'https://www.shellcheck.net/wiki/' . l:code
40         else
41             let l:link = 'https://github.com/buddy-works/dockerfile-linter/blob/master/Rules.md#' . l:code
42         endif
43
44         let l:detail = l:message . "\n\n" . l:link
45
46         call add(l:messages, {
47         \   'lnum': l:line,
48         \   'code': l:code,
49         \   'text': l:message,
50         \   'type': ale_linters#dockerfile#dockerlinter#GetType(l:type),
51         \   'detail': l:detail,
52         \})
53     endfor
54
55     return l:messages
56 endfunction
57
58 function! ale_linters#dockerfile#dockerlinter#GetCommand(buffer) abort
59     return '%e' . ale#Pad(ale#Var(a:buffer, 'dockerfile_dockerlinter_options'))
60     \   . ' -j -f'
61     \   . ' %t'
62 endfunction
63
64 call ale#linter#Define('dockerfile', {
65 \   'name': 'dockerlinter',
66 \   'executable': {b -> ale#Var(b, 'dockerfile_dockerlinter_executable')},
67 \   'command': function('ale_linters#dockerfile#dockerlinter#GetCommand'),
68 \   'callback': 'ale_linters#dockerfile#dockerlinter#Handle',
69 \})