2018-03-31 10:55:20 -04:00
|
|
|
" Author: Alistair Bill <@alibabzo>
|
2021-05-05 04:25:00 -04:00
|
|
|
" Author: Maximilian Bosch <maximilian@mbosch.me>
|
2018-03-31 10:55:20 -04:00
|
|
|
" Description: nix-instantiate linter for nix files
|
|
|
|
|
2021-05-05 04:25:00 -04:00
|
|
|
function! ale_linters#nix#nix#Command(buffer, output, meta) abort
|
|
|
|
let l:version = a:output[0][22:]
|
|
|
|
|
2022-08-08 09:45:56 -04:00
|
|
|
if l:version =~# '^\(2.[4-9]\|3\).*'
|
2021-05-05 04:25:00 -04:00
|
|
|
return 'nix-instantiate --log-format internal-json --parse -'
|
|
|
|
else
|
|
|
|
return 'nix-instantiate --parse -'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
function! ale_linters#nix#nix#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2021-05-05 04:25:00 -04:00
|
|
|
if empty(a:lines)
|
|
|
|
return l:output
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:lines[0] =~# '^@nix .*'
|
|
|
|
for l:line in a:lines
|
|
|
|
if l:line =~# '^@nix .*'
|
|
|
|
let l:result = json_decode(strpart(l:line, 4))
|
|
|
|
|
|
|
|
if has_key(l:result, 'column')
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'lnum': l:result.line,
|
|
|
|
\ 'col': l:result.column,
|
|
|
|
\ 'text': l:result.raw_msg
|
|
|
|
\})
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
let l:pattern = '^\(.\+\): \(.\+\) at .*:\(\d\+\):\(\d\+\)$'
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[3] + 0,
|
|
|
|
\ 'col': l:match[4] + 0,
|
|
|
|
\ 'text': l:match[1] . ': ' . substitute(l:match[2], ',$', '', ''),
|
|
|
|
\ 'type': l:match[1] =~# '^error' ? 'E' : 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
endif
|
2018-03-31 10:55:20 -04:00
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('nix', {
|
|
|
|
\ 'name': 'nix',
|
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\ 'executable': 'nix-instantiate',
|
2021-05-05 04:25:00 -04:00
|
|
|
\ 'command': {buffer -> ale#command#Run(
|
|
|
|
\ buffer,
|
|
|
|
\ 'nix-instantiate --version',
|
|
|
|
\ function('ale_linters#nix#nix#Command')
|
|
|
|
\ )},
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale_linters#nix#nix#Handle',
|
|
|
|
\})
|