mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
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
This commit is contained in:
41
ale_linters/terraform/checkov.vim
Normal file
41
ale_linters/terraform/checkov.vim
Normal file
@@ -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',
|
||||
\})
|
||||
Reference in New Issue
Block a user