summaryrefslogtreecommitdiff
path: root/ale_linters/terraform
diff options
context:
space:
mode:
authorthyme-87 <thyme-87@users.noreply.github.com>2021-12-11 12:51:26 +0100
committerGitHub <noreply@github.com>2021-12-11 20:51:26 +0900
commit091592bfb09e7e994bd860fa3776e8cf4346bf5a (patch)
treef5ad6b947024d89140b7452ea58fe3d2e99b5243 /ale_linters/terraform
parentb9744076a1603b37bc861e1aa885bbc052e0ed63 (diff)
downloadale-091592bfb09e7e994bd860fa3776e8cf4346bf5a.zip
add support for checkov for linting terraform files (#4006)
* add support for checkov for terraform * add tests for checkov handler * add basic linter config tests for checkov * update supported tools and languages lists * simplify ale_linters#terraform#checkov#Handle * ensure "-o json --quiet" is always set for checkov * add documentation for checkov including config options * fix tests after changing handling of default options for checkov * add checkov to list of tools in doc/ale.txt
Diffstat (limited to 'ale_linters/terraform')
-rw-r--r--ale_linters/terraform/checkov.vim41
1 files changed, 41 insertions, 0 deletions
diff --git a/ale_linters/terraform/checkov.vim b/ale_linters/terraform/checkov.vim
new file mode 100644
index 00000000..568b46e1
--- /dev/null
+++ b/ale_linters/terraform/checkov.vim
@@ -0,0 +1,41 @@
+" Author: Thyme-87 <thyme-87@posteo.me>
+" Description: use checkov for providing warnings via ale
+
+call ale#Set('terraform_checkov_executable', 'checkov')
+call ale#Set('terraform_checkov_options', '')
+
+function! ale_linters#terraform#checkov#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'terraform_checkov_executable')
+endfunction
+
+function! ale_linters#terraform#checkov#GetCommand(buffer) abort
+ return '%e ' . '-f %t -o json --quiet ' . ale#Var(a:buffer, 'terraform_checkov_options')
+endfunction
+
+function! ale_linters#terraform#checkov#Handle(buffer, lines) abort
+ let l:output = []
+
+ let l:results = get(get(ale#util#FuzzyJSONDecode(a:lines, {}), 'results', []), 'failed_checks', [])
+
+ for l:violation in l:results
+ call add(l:output, {
+ \ 'filename': l:violation['file_path'],
+ \ 'lnum': l:violation['file_line_range'][0],
+ \ 'end_lnum': l:violation['file_line_range'][1],
+ \ 'text': l:violation['check_name'] . ' [' . l:violation['check_id'] . ']',
+ \ 'detail': l:violation['check_id'] . ': ' . l:violation['check_name'] . "\n" .
+ \ 'For more information, see: '. l:violation['guideline'],
+ \ 'type': 'W',
+ \ })
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('terraform', {
+\ 'name': 'checkov',
+\ 'output_stream': 'stdout',
+\ 'executable': function('ale_linters#terraform#checkov#GetExecutable'),
+\ 'command': function('ale_linters#terraform#checkov#GetCommand'),
+\ 'callback': 'ale_linters#terraform#checkov#Handle',
+\})