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

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / jsonnet / jsonnetfmt.vim
1 " Authors: Trevor Whitney <trevorjwhitney@gmail.com> and Takuya Kosugiyama <re@itkq.jp>
2 " Description: jsonnetfmt for jsonnet files
3
4 call ale#Set('jsonnet_jsonnetfmt_executable', 'jsonnetfmt')
5 call ale#Set('jsonnet_jsonnetfmt_options', '')
6
7 function! ale_linters#jsonnet#jsonnetfmt#GetCommand(buffer) abort
8     let l:options = ale#Var(a:buffer, 'jsonnet_jsonnetfmt_options')
9
10     return '%e'
11     \   . ale#Pad(l:options)
12     \   . ' %t'
13 endfunction
14
15
16 function! ale_linters#jsonnet#jsonnetfmt#Handle(buffer, lines) abort
17     " Matches patterns line the following:
18     "
19     " STATIC ERROR: foo.jsonnet:22:3-12: expected token OPERATOR but got (IDENTIFIER, "bar")
20     " STATIC ERROR: hoge.jsonnet:20:3: unexpected: "}" while parsing terminal
21     let l:pattern = '^STATIC ERROR:[^:]*:\(\d\+\):\(\d\+\):*\(-\d\+\)* \(.*\)'
22     let l:output = []
23
24     for l:line in a:lines
25         let l:match = matchlist(l:line, l:pattern)
26
27         if len(l:match) == 0
28             continue
29         endif
30
31         " vcol is Needed to indicate that the column is a character.
32         call add(l:output, {
33         \   'bufnr': a:buffer,
34         \   'lnum': l:match[1] + 0,
35         \   'vcol': 0,
36         \   'col': l:match[2] + 0,
37         \   'text': l:match[4],
38         \   'type': 'E',
39         \   'nr': -1,
40         \})
41     endfor
42
43     return l:output
44 endfunction
45
46 call ale#linter#Define('jsonnet', {
47 \   'name': 'jsonnetfmt',
48 \   'output_stream': 'stderr',
49 \   'executable': {b -> ale#Var(b, 'jsonnet_jsonnetfmt_executable')},
50 \   'command': function('ale_linters#jsonnet#jsonnetfmt#GetCommand'),
51 \   'callback': 'ale_linters#jsonnet#jsonnetfmt#Handle',
52 \})