summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2021-01-30 18:20:49 +0900
committerGitHub <noreply@github.com>2021-01-30 18:20:49 +0900
commit2d07fa0cc2e5989f32e13dfee0cabfef9f765fdc (patch)
treea8e66b3aca0bb1d6741ac629f2842cf3ae029beb /ale_linters
parent7c44f4e403a85ac9707c121bff3ad08a65443f0c (diff)
parentdd1c665db26724ff70b72aca412896723d389126 (diff)
downloadale-2d07fa0cc2e5989f32e13dfee0cabfef9f765fdc.zip
Merge pull request #3566 from hsanson/2726-fix-terraform-linter
Fix 2726 - fix terraform linter.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/terraform/terraform.vim42
1 files changed, 26 insertions, 16 deletions
diff --git a/ale_linters/terraform/terraform.vim b/ale_linters/terraform/terraform.vim
index 0429cb7a..623fc2fd 100644
--- a/ale_linters/terraform/terraform.vim
+++ b/ale_linters/terraform/terraform.vim
@@ -9,30 +9,40 @@ endfunction
function! ale_linters#terraform#terraform#GetCommand(buffer) abort
return ale#Escape(ale_linters#terraform#terraform#GetExecutable(a:buffer))
- \ . ' fmt -no-color --check=true -'
+ \ . ' validate -no-color -json '
+endfunction
+
+function! ale_linters#terraform#terraform#GetType(severity) abort
+ if a:severity is? 'warning'
+ return 'W'
+ endif
+
+ return 'E'
endfunction
function! ale_linters#terraform#terraform#Handle(buffer, lines) abort
- let l:head = '^Error running fmt: In <standard input>: '
let l:output = []
- let l:patterns = [
- \ l:head.'At \(\d\+\):\(\d\+\): \(.*\)$',
- \ l:head.'\(.*\)$'
- \]
- for l:match in ale#util#GetMatches(a:lines, l:patterns)
- if len(l:match[2]) > 0
+ 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')
call add(l:output, {
- \ 'lnum': str2nr(l:match[1]),
- \ 'col': str2nr(l:match[2]),
- \ 'text': l:match[3],
- \ 'type': 'E',
+ \ 'filename': ale#path#GetAbsPath(l:dir, l:error['range']['filename']),
+ \ 'lnum': l:error['range']['start']['line'],
+ \ 'col': l:error['range']['start']['column'],
+ \ 'text': l:error['detail'],
+ \ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
\})
else
call add(l:output, {
- \ 'lnum': line('$'),
- \ 'text': l:match[1],
- \ 'type': 'E',
+ \ 'filename': l:file,
+ \ 'lnum': 0,
+ \ 'col': 0,
+ \ 'text': l:error['detail'],
+ \ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
\})
endif
endfor
@@ -42,7 +52,7 @@ endfunction
call ale#linter#Define('terraform', {
\ 'name': 'terraform',
-\ 'output_stream': 'stderr',
+\ 'output_stream': 'stdout',
\ 'executable': function('ale_linters#terraform#terraform#GetExecutable'),
\ 'command': function('ale_linters#terraform#terraform#GetCommand'),
\ 'callback': 'ale_linters#terraform#terraform#Handle',