diff options
author | jD91mZM2 <me@krake.one> | 2021-01-31 13:01:03 +0100 |
---|---|---|
committer | jD91mZM2 <me@krake.one> | 2021-01-31 13:01:03 +0100 |
commit | 4894c760c25e9f436a071ceb80a538fb0b23b306 (patch) | |
tree | 8d538edbbb776903437bc58ddce4e14e3a2129cb /ale_linters/json | |
parent | 2d07fa0cc2e5989f32e13dfee0cabfef9f765fdc (diff) | |
download | ale-4894c760c25e9f436a071ceb80a538fb0b23b306.zip |
Add jq linter for JSON diagnostics
Diffstat (limited to 'ale_linters/json')
-rw-r--r-- | ale_linters/json/jq.vim | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ale_linters/json/jq.vim b/ale_linters/json/jq.vim new file mode 100644 index 00000000..4cce0e98 --- /dev/null +++ b/ale_linters/json/jq.vim @@ -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', +\}) |