Add jq linter for JSON diagnostics
This commit is contained in:
parent
2d07fa0cc2
commit
4894c760c2
2 changed files with 49 additions and 0 deletions
34
ale_linters/json/jq.vim
Normal file
34
ale_linters/json/jq.vim
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
" Author: jD91mZM2 <me@krake.one>
|
||||||
|
|
||||||
|
call ale#Set('json_jq_executable', 'jq')
|
||||||
|
|
||||||
|
function! ale_linters#json#jq#GetCommand(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'json_jq_executable')
|
||||||
|
|
||||||
|
return ale#Var(a:buffer, 'json_jq_executable')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#json#jq#Handle(buffer, lines) abort
|
||||||
|
" Matches patterns like the following:
|
||||||
|
" parse error: Expected another key-value pair at line 4, column 3
|
||||||
|
let l:pattern = '^parse error: \(.\+\) at line \(\d\+\), column \(\d\+\)$'
|
||||||
|
let l:output = []
|
||||||
|
|
||||||
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'text': l:match[1],
|
||||||
|
\ 'lnum': l:match[2] + 0,
|
||||||
|
\ 'col': l:match[3] + 0,
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:output
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('json', {
|
||||||
|
\ 'name': 'jq',
|
||||||
|
\ 'executable': { b -> ale#Var(b, 'json_jq_executable') },
|
||||||
|
\ 'output_stream': 'stderr',
|
||||||
|
\ 'command': function('ale_linters#json#jq#GetCommand'),
|
||||||
|
\ 'callback': 'ale_linters#json#jq#Handle',
|
||||||
|
\})
|
15
test/test_jq_linter.vader
Normal file
15
test/test_jq_linter.vader
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Before:
|
||||||
|
runtime ale_linters/json/jq.vim
|
||||||
|
|
||||||
|
Execute (Should parse error correctly):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'col': 9,
|
||||||
|
\ 'text': 'Expected another array element',
|
||||||
|
\ }
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#json#jq#Handle(0, [
|
||||||
|
\ 'parse error: Expected another array element at line 1, column 9'
|
||||||
|
\ ])
|
Reference in a new issue