summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorlucas-str <32294068+lucas-str@users.noreply.github.com>2023-05-06 02:02:07 +0200
committerGitHub <noreply@github.com>2023-05-06 09:02:07 +0900
commit9fe9f115213d7e7bf52d06ebdc69c6df38b1120b (patch)
tree36afc7ede0bf275c71e4f043745d5e15b40860e0 /ale_linters
parent61248e1453dc6373160154e1f6855ffc510a7dfc (diff)
downloadale-9fe9f115213d7e7bf52d06ebdc69c6df38b1120b.zip
Add support for npm-groovy-lint (#4495)
* Add support for npm-groovy-lint * Add doc and tests for npm-groovy-lint * Use ale#util#FuzzyJSONDecode instead of json_decode
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/groovy/npmgroovylint.vim46
1 files changed, 46 insertions, 0 deletions
diff --git a/ale_linters/groovy/npmgroovylint.vim b/ale_linters/groovy/npmgroovylint.vim
new file mode 100644
index 00000000..4141bd25
--- /dev/null
+++ b/ale_linters/groovy/npmgroovylint.vim
@@ -0,0 +1,46 @@
+" Author: lucas-str <lucas.sturelle@ik.me>
+" Description: Integration of npm-groovy-lint for Groovy files.
+
+call ale#Set('groovy_npmgroovylint_executable', 'npm-groovy-lint')
+call ale#Set('groovy_npmgroovylint_options', '--loglevel warning')
+
+function! ale_linters#groovy#npmgroovylint#GetCommand(buffer) abort
+ let l:options = ale#Var(a:buffer, 'groovy_npmgroovylint_options')
+
+ return '%e --failon none --output json'
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+ \ . ' %t'
+endfunction
+
+function! ale_linters#groovy#npmgroovylint#Handle(buffer, lines) abort
+ let l:output = []
+ let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
+
+ for [l:filename, l:file] in items(get(l:json, 'files', {}))
+ for l:error in get(l:file, 'errors', [])
+ let l:output_line = {
+ \ 'filename': l:filename,
+ \ 'lnum': l:error.line,
+ \ 'text': l:error.msg,
+ \ 'type': toupper(l:error.severity[0]),
+ \}
+
+ if has_key(l:error, 'range')
+ let l:output_line.col = l:error.range.start.character
+ let l:output_line.end_col = l:error.range.end.character
+ let l:output_line.end_lnum = l:error.range.end.line
+ endif
+
+ call add(l:output, l:output_line)
+ endfor
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('groovy', {
+\ 'name': 'npm-groovy-lint',
+\ 'executable': {b -> ale#Var(b, 'groovy_npmgroovylint_executable')},
+\ 'command': function('ale_linters#groovy#npmgroovylint#GetCommand'),
+\ 'callback': 'ale_linters#groovy#npmgroovylint#Handle',
+\})