summaryrefslogtreecommitdiff
path: root/ale_linters/terraform
diff options
context:
space:
mode:
authorNathaniel Williams <nat@livewatch.com>2017-10-26 19:32:33 +0100
committerw0rp <devw0rp@gmail.com>2017-10-26 19:37:04 +0100
commite4456a4e0e9622baf2af30acd34a28963df5f4fa (patch)
tree5ae24057300cbcafa576f6ca81903168133f6659 /ale_linters/terraform
parent6ed456f99c46ad6853fdd893344e94060ce9f6c3 (diff)
downloadale-e4456a4e0e9622baf2af30acd34a28963df5f4fa.zip
Add tflint fot Terraform
Diffstat (limited to 'ale_linters/terraform')
-rw-r--r--ale_linters/terraform/tflint.vim61
1 files changed, 61 insertions, 0 deletions
diff --git a/ale_linters/terraform/tflint.vim b/ale_linters/terraform/tflint.vim
new file mode 100644
index 00000000..f66a9635
--- /dev/null
+++ b/ale_linters/terraform/tflint.vim
@@ -0,0 +1,61 @@
+" 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,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+function! ale_linters#terraform#tflint#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'terraform_tflint_executable')
+endfunction
+
+function! ale_linters#terraform#tflint#GetCommand(buffer) abort
+ let l:cmd = ale#Escape(ale#Var(a:buffer, 'terraform_tflint_executable'))
+
+ let l:config_file = ale#path#FindNearestFile(a:buffer, '.tflint.hcl')
+ 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')
+ if !empty(l:opts)
+ let l:cmd .= ' ' . l:opts
+ endif
+
+ let l:cmd .= ' -f json'
+
+ return l:cmd
+endfunction
+
+call ale#linter#Define('terraform', {
+\ 'name': 'tflint',
+\ 'executable_callback': 'ale_linters#terraform#tflint#GetExecutable',
+\ 'command_callback': 'ale_linters#terraform#tflint#GetCommand',
+\ 'callback': 'ale_linters#terraform#tflint#Handle',
+\})
+
+" vim:sw=4