]> git.madduck.net Git - etc/vim.git/blob - ale_linters/terraform/checkov.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 / terraform / checkov.vim
1 " Author: Thyme-87 <thyme-87@posteo.me>
2 " Description: use checkov for providing warnings via ale
3
4 call ale#Set('terraform_checkov_executable', 'checkov')
5 call ale#Set('terraform_checkov_options', '')
6
7 function! ale_linters#terraform#checkov#GetExecutable(buffer) abort
8     return ale#Var(a:buffer, 'terraform_checkov_executable')
9 endfunction
10
11 function! ale_linters#terraform#checkov#GetCommand(buffer) abort
12     return '%e ' . '-f %t -o json --quiet ' . ale#Var(a:buffer, 'terraform_checkov_options')
13 endfunction
14
15 function! ale_linters#terraform#checkov#Handle(buffer, lines) abort
16     let l:output = []
17
18     let l:results = get(get(ale#util#FuzzyJSONDecode(a:lines, {}), 'results', []), 'failed_checks', [])
19
20     for l:violation in l:results
21         call add(l:output, {
22         \   'filename': l:violation['file_path'],
23         \   'lnum': l:violation['file_line_range'][0],
24         \   'end_lnum': l:violation['file_line_range'][1],
25         \   'text': l:violation['check_name'] . ' [' . l:violation['check_id'] . ']',
26         \   'detail': l:violation['check_id'] . ': ' . l:violation['check_name'] . "\n" .
27         \             'For more information, see: '. l:violation['guideline'],
28         \   'type': 'W',
29         \   })
30     endfor
31
32     return l:output
33 endfunction
34
35 call ale#linter#Define('terraform', {
36 \   'name': 'checkov',
37 \   'output_stream': 'stdout',
38 \   'executable': function('ale_linters#terraform#checkov#GetExecutable'),
39 \   'command': function('ale_linters#terraform#checkov#GetCommand'),
40 \   'callback': 'ale_linters#terraform#checkov#Handle',
41 \})