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 " Author: Nat Williams <nat.williams@gmail.com>
2 " Description: tflint for Terraform files
4 " See: https://www.terraform.io/
5 " https://github.com/wata727/tflint
7 call ale#Set('terraform_tflint_options', '')
8 call ale#Set('terraform_tflint_executable', 'tflint')
10 function! ale_linters#terraform#tflint#Handle(buffer, lines) abort
12 let l:pattern = '\v^(.*):(\d+),(\d+)-(\d+)?,?(\d+): (.{-1,}); (.+)$'
13 let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
15 " This is a rough test for tflint's output format
16 " On versions prior to 0.11 it outputs all errors as a single level list
17 if type(l:json) is v:t_list
19 if l:error.type is# 'ERROR'
21 elseif l:error.type is# 'NOTICE'
28 \ 'lnum': l:error.line,
29 \ 'text': l:error.message,
31 \ 'code': l:error.detector,
35 for l:error in get(l:json, 'errors', [])
36 for l:match in ale#util#GetMatches(l:error.message, [l:pattern])
38 let l:match[4] = l:match[2]
42 \ 'filename': l:match[1],
43 \ 'lnum': str2nr(l:match[2]),
44 \ 'col': str2nr(l:match[3]),
45 \ 'end_lnum': str2nr(l:match[4]),
46 \ 'end_col': str2nr(l:match[5]),
54 for l:error in get(l:json, 'issues', [])
55 if l:error.rule.severity is# 'ERROR'
57 elseif l:error.rule.severity is# 'NOTICE'
64 \ 'filename': l:error.range.filename,
65 \ 'lnum': l:error.range.start.line,
66 \ 'col': l:error.range.start.column,
67 \ 'end_lnum': l:error.range.end.line,
68 \ 'end_col': l:error.range.end.column,
69 \ 'text': l:error.message,
70 \ 'code': l:error.rule.name,
79 function! ale_linters#terraform#tflint#GetCommand(buffer) abort
82 let l:config_file = ale#path#FindNearestFile(a:buffer, '.tflint.hcl')
84 if !empty(l:config_file)
85 let l:cmd .= ' --config ' . ale#Escape(l:config_file)
88 let l:opts = ale#Var(a:buffer, 'terraform_tflint_options')
91 let l:cmd .= ' ' . l:opts
94 let l:cmd .= ' -f json'
99 call ale#linter#Define('terraform', {
101 \ 'executable': {b -> ale#Var(b, 'terraform_tflint_executable')},
103 \ 'command': function('ale_linters#terraform#tflint#GetCommand'),
104 \ 'callback': 'ale_linters#terraform#tflint#Handle',