2019-05-23 13:12:36 +00:00
|
|
|
" Author: Keith Maxwell <keith.maxwell@gmail.com>
|
|
|
|
" Description: terraform fmt to check for errors
|
|
|
|
|
|
|
|
call ale#Set('terraform_terraform_executable', 'terraform')
|
|
|
|
|
|
|
|
function! ale_linters#terraform#terraform#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'terraform_terraform_executable')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#terraform#terraform#GetCommand(buffer) abort
|
|
|
|
return ale#Escape(ale_linters#terraform#terraform#GetExecutable(a:buffer))
|
2021-01-30 08:11:12 +00:00
|
|
|
\ . ' validate -no-color -json '
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#terraform#terraform#GetType(severity) abort
|
|
|
|
if a:severity is? 'warning'
|
|
|
|
return 'W'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 'E'
|
2019-05-23 13:12:36 +00:00
|
|
|
endfunction
|
|
|
|
|
2021-03-04 11:45:33 +00:00
|
|
|
function! ale_linters#terraform#terraform#GetDetail(error) abort
|
|
|
|
return get(a:error, 'detail', get(a:error, 'summary', ''))
|
|
|
|
endfunction
|
|
|
|
|
2019-05-23 13:12:36 +00:00
|
|
|
function! ale_linters#terraform#terraform#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2021-01-30 08:11:12 +00:00
|
|
|
let l:errors = ale#util#FuzzyJSONDecode(a:lines, {'diagnostics': []})
|
|
|
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
|
|
|
let l:file = expand('#' . a:buffer . ':p')
|
|
|
|
|
|
|
|
for l:error in l:errors['diagnostics']
|
|
|
|
if has_key(l:error, 'range')
|
2019-05-23 13:12:36 +00:00
|
|
|
call add(l:output, {
|
2021-01-30 08:11:12 +00:00
|
|
|
\ 'filename': ale#path#GetAbsPath(l:dir, l:error['range']['filename']),
|
|
|
|
\ 'lnum': l:error['range']['start']['line'],
|
|
|
|
\ 'col': l:error['range']['start']['column'],
|
2021-03-04 11:45:33 +00:00
|
|
|
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
2021-01-30 08:11:12 +00:00
|
|
|
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
2019-05-23 13:12:36 +00:00
|
|
|
\})
|
|
|
|
else
|
|
|
|
call add(l:output, {
|
2021-01-30 08:11:12 +00:00
|
|
|
\ 'filename': l:file,
|
|
|
|
\ 'lnum': 0,
|
|
|
|
\ 'col': 0,
|
2021-03-04 11:45:33 +00:00
|
|
|
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
2021-01-30 08:11:12 +00:00
|
|
|
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
2019-05-23 13:12:36 +00:00
|
|
|
\})
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('terraform', {
|
|
|
|
\ 'name': 'terraform',
|
2021-01-30 08:11:12 +00:00
|
|
|
\ 'output_stream': 'stdout',
|
2019-05-23 13:12:36 +00:00
|
|
|
\ 'executable': function('ale_linters#terraform#terraform#GetExecutable'),
|
|
|
|
\ 'command': function('ale_linters#terraform#terraform#GetCommand'),
|
|
|
|
\ 'callback': 'ale_linters#terraform#terraform#Handle',
|
|
|
|
\})
|