2017-10-26 14:32:33 -04:00
|
|
|
" Author: Nat Williams <nat.williams@gmail.com>
|
|
|
|
" Description: tflint for Terraform files
|
|
|
|
"
|
|
|
|
" See: https://www.terraform.io/
|
|
|
|
" https://github.com/wata727/tflint
|
|
|
|
|
|
|
|
call ale#Set('terraform_tflint_options', '')
|
|
|
|
call ale#Set('terraform_tflint_executable', 'tflint')
|
|
|
|
|
|
|
|
function! ale_linters#terraform#tflint#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
|
|
|
if l:error.type is# 'ERROR'
|
|
|
|
let l:type = 'E'
|
|
|
|
elseif l:error.type is# 'NOTICE'
|
|
|
|
let l:type = 'I'
|
|
|
|
else
|
|
|
|
let l:type = 'W'
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:error.line,
|
|
|
|
\ 'text': l:error.message,
|
|
|
|
\ 'type': l:type,
|
2017-11-19 08:37:56 -05:00
|
|
|
\ 'code': l:error.detector,
|
2017-10-26 14:32:33 -04:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#terraform#tflint#GetCommand(buffer) abort
|
2018-08-02 18:44:12 -04:00
|
|
|
let l:cmd = '%e'
|
2017-10-26 14:32:33 -04:00
|
|
|
|
|
|
|
let l:config_file = ale#path#FindNearestFile(a:buffer, '.tflint.hcl')
|
2018-08-02 18:44:12 -04:00
|
|
|
|
2017-10-26 14:32:33 -04:00
|
|
|
if !empty(l:config_file)
|
|
|
|
let l:cmd .= ' --config ' . ale#Escape(l:config_file)
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:opts = ale#Var(a:buffer, 'terraform_tflint_options')
|
2018-09-04 11:51:18 -04:00
|
|
|
|
2017-10-26 14:32:33 -04:00
|
|
|
if !empty(l:opts)
|
|
|
|
let l:cmd .= ' ' . l:opts
|
|
|
|
endif
|
|
|
|
|
2017-10-26 15:14:28 -04:00
|
|
|
let l:cmd .= ' -f json %t'
|
2017-10-26 14:32:33 -04:00
|
|
|
|
|
|
|
return l:cmd
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('terraform', {
|
|
|
|
\ 'name': 'tflint',
|
2019-02-22 13:05:04 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'terraform_tflint_executable')},
|
|
|
|
\ 'command': function('ale_linters#terraform#tflint#GetCommand'),
|
2017-10-26 14:32:33 -04:00
|
|
|
\ 'callback': 'ale_linters#terraform#tflint#Handle',
|
|
|
|
\})
|