mirror of https://github.com/dense-analysis/ale
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
This commit is contained in:
parent
61248e1453
commit
9fe9f11521
|
@ -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',
|
||||
\})
|
|
@ -610,6 +610,11 @@ let s:default_registry = {
|
|||
\ 'function': 'ale#fixers#rustywind#Fix',
|
||||
\ 'suggested_filetypes': ['html'],
|
||||
\ 'description': 'Sort Tailwind CSS classes',
|
||||
\ },
|
||||
\ 'npm-groovy-lint': {
|
||||
\ 'function': 'ale#fixers#npmgroovylint#Fix',
|
||||
\ 'suggested_filetypes': ['groovy'],
|
||||
\ 'description': 'Fix Groovy files with npm-groovy-fix.',
|
||||
\ }
|
||||
\}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
" Author: lucas-str <lucas.sturelle@ik.me>
|
||||
" Description: Integration of npm-groovy-lint for Groovy files.
|
||||
|
||||
call ale#Set('groovy_npmgroovylint_fix_options', '--fix')
|
||||
|
||||
function! ale#fixers#npmgroovylint#Fix(buffer) abort
|
||||
let l:executable = ale#Var(a:buffer, 'groovy_npmgroovylint_executable')
|
||||
let l:options = ale#Var(a:buffer, 'groovy_npmgroovylint_fix_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' %t',
|
||||
\ 'read_temporary_file': 1,
|
||||
\}
|
||||
endfunction
|
|
@ -43,6 +43,7 @@ let s:default_ale_linters = {
|
|||
\ 'csh': ['shell'],
|
||||
\ 'elixir': ['credo', 'dialyxir', 'dogma'],
|
||||
\ 'go': ['gofmt', 'golint', 'gopls', 'govet'],
|
||||
\ 'groovy': ['npm-groovy-lint'],
|
||||
\ 'hack': ['hack'],
|
||||
\ 'help': [],
|
||||
\ 'inko': ['inko'],
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
===============================================================================
|
||||
ALE Groovy Integration *ale-groovy-options*
|
||||
|
||||
|
||||
===============================================================================
|
||||
Integration Information
|
||||
|
||||
Linting and fixing of Groovy files is enabled with the integration of
|
||||
`npm-groovy-lint`.
|
||||
|
||||
|
||||
===============================================================================
|
||||
npm-groovy-lint *ale-groovy-npm-groovy-lint*
|
||||
|
||||
g:ale_groovy_npmgroovylint_executable *g:ale_groovy_npmgroovylint_executable*
|
||||
*b:ale_groovy_npmgroovylint_executable*
|
||||
Type: |String|
|
||||
Default: `'npm-groovy-lint'`
|
||||
|
||||
Location of the npm-groovy-lint binary file.
|
||||
|
||||
|
||||
g:ale_groovy_npmgroovylint_options *g:ale_groovy_npmgroovylint_options*
|
||||
*b:ale_groovy_npmgroovylint_options*
|
||||
Type: |String|
|
||||
Default: `'--loglevel warning'`
|
||||
|
||||
Additional npm-groovy-lint linter options.
|
||||
|
||||
|
||||
g:ale_groovy_npmgroovylint_fix_options *g:ale_groovy_npmgroovylint_fix_options*
|
||||
*b:ale_groovy_npmgroovylint_fix_options*
|
||||
Type: |String|
|
||||
Default: `'--fix'`
|
||||
|
||||
This variable can be used to configure fixing with npm-groovy-lint. It must
|
||||
contain either `--fix` or `--format` for the fixer to work. See
|
||||
`npm-groovy-lint --help` for more information on possible fix rules.
|
||||
|
||||
|
||||
===============================================================================
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
|
@ -223,6 +223,8 @@ Notes:
|
|||
* `eslint`
|
||||
* `gqlint`
|
||||
* `prettier`
|
||||
* Groovy
|
||||
* `npm-groovy-lint`
|
||||
* Hack
|
||||
* `hack`
|
||||
* `hackfmt`
|
||||
|
|
|
@ -1642,6 +1642,7 @@ g:ale_linters *g:ale_linters*
|
|||
\ 'csh': ['shell'],
|
||||
\ 'elixir': ['credo', 'dialyxir', 'dogma'],
|
||||
\ 'go': ['gofmt', 'golint', 'gopls', 'govet'],
|
||||
\ 'groovy': ['npm-groovy-lint'],
|
||||
\ 'hack': ['hack'],
|
||||
\ 'help': [],
|
||||
\ 'inko': ['inko'],
|
||||
|
@ -2995,6 +2996,8 @@ documented in additional help files.
|
|||
eslint................................|ale-graphql-eslint|
|
||||
gqlint................................|ale-graphql-gqlint|
|
||||
prettier..............................|ale-graphql-prettier|
|
||||
groovy..................................|ale-groovy-options|
|
||||
npm-groovy-lint.......................|ale-groovy-npm-groovy-lint|
|
||||
hack....................................|ale-hack-options|
|
||||
hack..................................|ale-hack-hack|
|
||||
hackfmt...............................|ale-hack-hackfmt|
|
||||
|
|
|
@ -232,6 +232,8 @@ formatting.
|
|||
* [eslint](http://eslint.org/)
|
||||
* [gqlint](https://github.com/happylinks/gqlint)
|
||||
* [prettier](https://github.com/prettier/prettier)
|
||||
* Groovy
|
||||
* [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint)
|
||||
* Hack
|
||||
* [hack](http://hacklang.org/)
|
||||
* [hackfmt](https://github.com/facebook/hhvm/tree/master/hphp/hack/hackfmt)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
Before:
|
||||
Save b:ale_groovy_npmgroovylint_fix_options
|
||||
|
||||
call ale#assert#SetUpFixerTest('groovy', 'npm-groovy-lint')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#assert#TearDownFixerTest()
|
||||
|
||||
Execute(The callback should return the correct default values):
|
||||
AssertFixer {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('npm-groovy-lint') . ' --fix %t',
|
||||
\ }
|
||||
|
||||
Execute(The callback should include custom options):
|
||||
let b:ale_groovy_npmgroovylint_fix_options = '--format'
|
||||
|
||||
AssertFixer {
|
||||
\ 'read_temporary_file': 1,
|
||||
\ 'command': ale#Escape('npm-groovy-lint') . ' --format %t',
|
||||
\ }
|
|
@ -0,0 +1,63 @@
|
|||
Before:
|
||||
runtime ale_linters/groovy/npmgroovylint.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The npm-groovy-lint handler should parse JSON):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'col': 0,
|
||||
\ 'end_col': 1,
|
||||
\ 'end_lnum': 2,
|
||||
\ 'filename': 'test2.groovy',
|
||||
\ 'lnum': 2,
|
||||
\ 'text': 'Some error message',
|
||||
\ 'type': 'E',
|
||||
\ },
|
||||
\ {
|
||||
\ 'filename': 'test.groovy',
|
||||
\ 'lnum': 1,
|
||||
\ 'text': 'Some warning message',
|
||||
\ 'type': 'W',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#groovy#npmgroovylint#Handle(bufnr(''), [
|
||||
\ '{',
|
||||
\ ' "files" : {',
|
||||
\ ' "test.groovy" : {',
|
||||
\ ' "errors" : [',
|
||||
\ ' {',
|
||||
\ ' "id" : 0,',
|
||||
\ ' "line" : 1,',
|
||||
\ ' "msg" : "Some warning message",',
|
||||
\ ' "rule" : "SomeRule",',
|
||||
\ ' "severity" : "warning"',
|
||||
\ ' }',
|
||||
\ ' ]',
|
||||
\ ' },',
|
||||
\ ' "test2.groovy": {',
|
||||
\ ' "errors": [',
|
||||
\ ' {',
|
||||
\ ' "id" : 1,',
|
||||
\ ' "line" : 2,',
|
||||
\ ' "msg" : "Some error message",',
|
||||
\ ' "range" : {',
|
||||
\ ' "end" : {',
|
||||
\ ' "character" : 1,',
|
||||
\ ' "line" : 2',
|
||||
\ ' },',
|
||||
\ ' "start" : {',
|
||||
\ ' "character" : 0,',
|
||||
\ ' "line" : 2',
|
||||
\ ' }',
|
||||
\ ' },',
|
||||
\ ' "rule" : "SomeOtherRule",',
|
||||
\ ' "severity" : "error"',
|
||||
\ ' }',
|
||||
\ ' ]',
|
||||
\ ' }',
|
||||
\ ' }',
|
||||
\ '}',
|
||||
\ ])
|
|
@ -0,0 +1,20 @@
|
|||
Before:
|
||||
Save b:ale_groovy_npmgroovylint_options
|
||||
|
||||
call ale#assert#SetUpLinterTest('groovy', 'npmgroovylint')
|
||||
call ale#test#SetFilename('test.groovy')
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The default npm-groovy-lint command should be correct):
|
||||
AssertLinter 'npm-groovy-lint',
|
||||
\ ale#Escape('npm-groovy-lint') . ' --failon none --output json --loglevel warning %t'
|
||||
|
||||
Execute(Default options should be configurable):
|
||||
let b:ale_groovy_npmgroovylint_options = '--loglevel info'
|
||||
|
||||
AssertLinter 'npm-groovy-lint',
|
||||
\ ale#Escape('npm-groovy-lint') . ' --failon none --output json --loglevel info %t'
|
Loading…
Reference in New Issue