]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/nix/nix.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 '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / nix / nix.vim
1 " Author: Alistair Bill <@alibabzo>
2 " Author: Maximilian Bosch <maximilian@mbosch.me>
3 " Description: nix-instantiate linter for nix files
4
5 function! ale_linters#nix#nix#Command(buffer, output, meta) abort
6     let l:version = a:output[0][22:]
7
8     if l:version =~# '^\(1\|2.[0-3]\.\).*'
9         return 'nix-instantiate --parse -'
10     else
11         return 'nix-instantiate --log-format internal-json --parse -'
12     endif
13 endfunction
14
15 function! ale_linters#nix#nix#Handle(buffer, lines) abort
16     let l:output = []
17
18     if empty(a:lines)
19         return l:output
20     endif
21
22     if a:lines[0] =~# '^@nix .*'
23         for l:line in a:lines
24             if l:line =~# '^@nix .*'
25                 let l:result = json_decode(strpart(l:line, 4))
26
27                 if has_key(l:result, 'column')
28                     call add(l:output, {
29                     \     'type': 'E',
30                     \     'lnum': l:result.line,
31                     \     'col': l:result.column,
32                     \     'text': substitute(l:result.raw_msg, '\e\[[0-9;]*m', '', 'g'),
33                     \})
34                 endif
35             endif
36         endfor
37     else
38         let l:pattern = '^\(.\+\): \(.\+\) at .*:\(\d\+\):\(\d\+\)$'
39
40         for l:match in ale#util#GetMatches(a:lines, l:pattern)
41             call add(l:output, {
42             \   'lnum': l:match[3] + 0,
43             \   'col': l:match[4] + 0,
44             \   'text': l:match[1] . ': ' . substitute(l:match[2], ',$', '', ''),
45             \   'type': l:match[1] =~# '^error' ? 'E' : 'W',
46             \})
47         endfor
48     endif
49
50     return l:output
51 endfunction
52
53 call ale#linter#Define('nix', {
54 \   'name': 'nix',
55 \   'output_stream': 'stderr',
56 \   'executable': 'nix-instantiate',
57 \   'command': {buffer -> ale#command#Run(
58 \       buffer,
59 \       'nix-instantiate --version',
60 \       function('ale_linters#nix#nix#Command')
61 \   )},
62 \   'callback': 'ale_linters#nix#nix#Handle',
63 \})