summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2021-02-06 21:29:51 +0900
committerGitHub <noreply@github.com>2021-02-06 21:29:51 +0900
commitcf53eb3667edddf5708114aa0e617403d5dcd75b (patch)
tree325af191aa4206be412d3b3b8f18bbc55b20bc59
parent787ab2a36684838698a0173f29e82715420f117c (diff)
parent27130efc655dcba17c84cd4f8d30b6985c574441 (diff)
downloadale-cf53eb3667edddf5708114aa0e617403d5dcd75b.zip
Merge pull request #3568 from jD91mZM2/jq
Add jq linter for JSON diagnostics
-rw-r--r--ale_linters/json/jq.vim32
-rw-r--r--test/command_callback/test_jq_command_callback.vader8
-rw-r--r--test/test_jq_linter.vader18
3 files changed, 58 insertions, 0 deletions
diff --git a/ale_linters/json/jq.vim b/ale_linters/json/jq.vim
new file mode 100644
index 00000000..dd6ed0a6
--- /dev/null
+++ b/ale_linters/json/jq.vim
@@ -0,0 +1,32 @@
+" Author: jD91mZM2 <me@krake.one>
+
+function! ale_linters#json#jq#GetCommand(buffer) abort
+ let l:executable = ale#fixers#jq#GetExecutable(a:buffer)
+
+ return ale#Escape(l: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': function('ale#fixers#jq#GetExecutable'),
+\ 'output_stream': 'stderr',
+\ 'command': function('ale_linters#json#jq#GetCommand'),
+\ 'callback': 'ale_linters#json#jq#Handle',
+\})
diff --git a/test/command_callback/test_jq_command_callback.vader b/test/command_callback/test_jq_command_callback.vader
new file mode 100644
index 00000000..20c3db5b
--- /dev/null
+++ b/test/command_callback/test_jq_command_callback.vader
@@ -0,0 +1,8 @@
+Before:
+ call ale#assert#SetUpLinterTest('json', 'jq')
+
+After:
+ call ale#assert#TearDownLinterTest()
+
+Execute(The default command should be correct):
+ AssertLinter 'jq', ale#Escape('jq')
diff --git a/test/test_jq_linter.vader b/test/test_jq_linter.vader
new file mode 100644
index 00000000..cbe23b96
--- /dev/null
+++ b/test/test_jq_linter.vader
@@ -0,0 +1,18 @@
+Before:
+ runtime ale_linters/json/jq.vim
+
+After:
+ call ale#linter#Reset()
+
+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'
+ \ ])