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.
1 " Description: tfsec for Terraform files
3 " See: https://www.terraform.io/
4 " https://github.com/aquasecurity/tfsec
6 call ale#Set('terraform_tfsec_options', '')
7 call ale#Set('terraform_tfsec_executable', 'tfsec')
9 let s:separator = has('win32') ? '\' : '/'
11 function! ale_linters#terraform#tfsec#Handle(buffer, lines) abort
13 let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
15 " if there's no warning, 'result' is `null`.
16 if empty(get(l:json, 'results'))
20 for l:result in get(l:json, 'results', [])
21 if l:result.severity is# 'LOW'
23 elseif l:result.severity is# 'CRITICAL'
30 \ 'filename': l:result.location.filename,
31 \ 'lnum': l:result.location.start_line,
32 \ 'end_lnum': l:result.location.end_line,
33 \ 'text': l:result.description,
34 \ 'code': l:result.long_id,
42 " Construct command arguments to tfsec with `terraform_tfsec_options`.
43 function! ale_linters#terraform#tfsec#GetCommand(buffer) abort
46 let l:config = ale_linters#terraform#tfsec#FindConfig(a:buffer)
49 let l:cmd .= ' --config-file ' . l:config
52 let l:opts = ale#Var(a:buffer, 'terraform_tfsec_options')
55 let l:cmd .= ' ' . l:opts
58 let l:cmd .= ' --format json'
63 " Find the nearest configuration file of tfsec.
64 function! ale_linters#terraform#tfsec#FindConfig(buffer) abort
65 let l:config_dir = ale#path#FindNearestDirectory(a:buffer, '.tfsec')
67 if !empty(l:config_dir)
68 " https://aquasecurity.github.io/tfsec/v1.28.0/guides/configuration/config/
69 for l:basename in ['config.yml', 'config.json']
70 let l:config = ale#path#Simplify(join([l:config_dir, l:basename], s:separator))
72 if filereadable(l:config)
73 return ale#Escape(l:config)
81 call ale#linter#Define('terraform', {
83 \ 'executable': {b -> ale#Var(b, 'terraform_tfsec_executable')},
85 \ 'command': function('ale_linters#terraform#tfsec#GetCommand'),
86 \ 'callback': 'ale_linters#terraform#tfsec#Handle',