]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/terraform/terraform.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / terraform / terraform.vim
1 " Author: Keith Maxwell <keith.maxwell@gmail.com>
2 " Description: terraform fmt to check for errors
3
4 call ale#Set('terraform_terraform_executable', 'terraform')
5
6 function! ale_linters#terraform#terraform#GetExecutable(buffer) abort
7     return ale#Var(a:buffer, 'terraform_terraform_executable')
8 endfunction
9
10 function! ale_linters#terraform#terraform#GetCommand(buffer) abort
11     return ale#Escape(ale_linters#terraform#terraform#GetExecutable(a:buffer))
12     \   . ' validate -no-color -json '
13 endfunction
14
15 function! ale_linters#terraform#terraform#GetType(severity) abort
16     if a:severity is? 'warning'
17         return 'W'
18     endif
19
20     return 'E'
21 endfunction
22
23 function! ale_linters#terraform#terraform#GetDetail(error) abort
24     let l:detail = get(a:error, 'detail', '')
25
26     if strlen(l:detail) > 0
27         return l:detail
28     else
29         return get(a:error, 'summary', '')
30     endif
31 endfunction
32
33 function! ale_linters#terraform#terraform#Handle(buffer, lines) abort
34     let l:output = []
35
36     let l:errors = ale#util#FuzzyJSONDecode(a:lines, {'diagnostics': []})
37     let l:dir = expand('#' . a:buffer . ':p:h')
38     let l:file = expand('#' . a:buffer . ':p')
39
40     for l:error in l:errors['diagnostics']
41         if has_key(l:error, 'range')
42             call add(l:output, {
43             \   'filename': ale#path#GetAbsPath(l:dir, l:error['range']['filename']),
44             \   'lnum': l:error['range']['start']['line'],
45             \   'col': l:error['range']['start']['column'],
46             \   'text': ale_linters#terraform#terraform#GetDetail(l:error),
47             \   'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
48             \})
49         else
50             call add(l:output, {
51             \   'filename': l:file,
52             \   'lnum': 0,
53             \   'col': 0,
54             \   'text': ale_linters#terraform#terraform#GetDetail(l:error),
55             \   'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
56             \})
57         endif
58     endfor
59
60     return l:output
61 endfunction
62
63 call ale#linter#Define('terraform', {
64 \   'name': 'terraform',
65 \   'output_stream': 'stdout',
66 \   'executable': function('ale_linters#terraform#terraform#GetExecutable'),
67 \   'command': function('ale_linters#terraform#terraform#GetCommand'),
68 \   'callback': 'ale_linters#terraform#terraform#Handle',
69 \})