]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/jsonnet/jsonnet_lint.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:

Merge commit '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / jsonnet / jsonnet_lint.vim
1 " Author: Trevor Whitney <trevorjwhitney@gmail.com>
2 " Description: jsonnet-lint for jsonnet files
3
4 call ale#Set('jsonnet_jsonnet_lint_executable', 'jsonnet-lint')
5 call ale#Set('jsonnet_jsonnet_lint_options', '')
6
7 function! ale_linters#jsonnet#jsonnet_lint#GetCommand(buffer) abort
8     let l:options = ale#Var(a:buffer, 'jsonnet_jsonnet_lint_options')
9
10     return '%e'
11     \   . ale#Pad(l:options)
12     \   . ' %t'
13 endfunction
14
15
16 function! ale_linters#jsonnet#jsonnet_lint#Handle(buffer, lines) abort
17     " Matches patterns line the following:
18     "
19     " ERROR: foo.jsonnet:22:3-12 expected token OPERATOR but got (IDENTIFIER, "bar")
20     " ERROR: hoge.jsonnet:20:3 unexpected: "}" while parsing terminal
21     " ERROR: main.jsonnet:212:1-14 Expected , or ; but got (IDENTIFIER, "older_cluster")
22     let l:pattern = '^ERROR: [^:]*:\(\d\+\):\(\d\+\)\(-\d\+\)* \(.*\)'
23     let l:output = []
24
25     for l:line in a:lines
26         let l:match = matchlist(l:line, l:pattern)
27
28         if len(l:match) == 0
29             continue
30         endif
31
32         let line_number = l:match[1] + 0
33         let column = l:match[2] + 0
34         " l:match[3] has optional -14, when linter is showing a range
35         let text = l:match[4]
36
37
38         " vcol is Needed to indicate that the column is a character.
39         call add(l:output, {
40         \   'bufnr': a:buffer,
41         \   'lnum': line_number,
42         \   'vcol': 0,
43         \   'col': column,
44         \   'text': text,
45         \   'type': 'E',
46         \   'nr': -1,
47         \})
48     endfor
49
50     return l:output
51 endfunction
52
53 call ale#linter#Define('jsonnet', {
54 \   'name': 'jsonnet_lint',
55 \   'output_stream': 'stderr',
56 \   'executable': {b -> ale#Var(b, 'jsonnet_jsonnet_lint_executable')},
57 \   'command': function('ale_linters#jsonnet#jsonnet_lint#GetCommand'),
58 \   'callback': 'ale_linters#jsonnet#jsonnet_lint#Handle',
59 \})