summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/groovy/npmgroovylint.vim46
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/npmgroovylint.vim16
-rw-r--r--autoload/ale/linter.vim1
-rw-r--r--doc/ale-groovy.txt42
-rw-r--r--doc/ale-supported-languages-and-tools.txt2
-rw-r--r--doc/ale.txt3
-rw-r--r--supported-tools.md2
-rw-r--r--test/fixers/test_npmgroovylint_fixer_callback.vader23
-rw-r--r--test/handler/test_npmgroovylint_handler.vader63
-rw-r--r--test/linter/test_npmgroovylit.vader20
11 files changed, 223 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',
+\})
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 66cdc707..2f7edba8 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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.',
\ }
\}
diff --git a/autoload/ale/fixers/npmgroovylint.vim b/autoload/ale/fixers/npmgroovylint.vim
new file mode 100644
index 00000000..39e43cf6
--- /dev/null
+++ b/autoload/ale/fixers/npmgroovylint.vim
@@ -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
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index d90deace..8b943ea0 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -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'],
diff --git a/doc/ale-groovy.txt b/doc/ale-groovy.txt
new file mode 100644
index 00000000..cc5e8881
--- /dev/null
+++ b/doc/ale-groovy.txt
@@ -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:
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 6369224a..571322f4 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -223,6 +223,8 @@ Notes:
* `eslint`
* `gqlint`
* `prettier`
+* Groovy
+ * `npm-groovy-lint`
* Hack
* `hack`
* `hackfmt`
diff --git a/doc/ale.txt b/doc/ale.txt
index 76f00c43..a167f214 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index a69e8a76..fd906093 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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)
diff --git a/test/fixers/test_npmgroovylint_fixer_callback.vader b/test/fixers/test_npmgroovylint_fixer_callback.vader
new file mode 100644
index 00000000..a4b1ee9a
--- /dev/null
+++ b/test/fixers/test_npmgroovylint_fixer_callback.vader
@@ -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',
+ \ }
diff --git a/test/handler/test_npmgroovylint_handler.vader b/test/handler/test_npmgroovylint_handler.vader
new file mode 100644
index 00000000..e0dae6d2
--- /dev/null
+++ b/test/handler/test_npmgroovylint_handler.vader
@@ -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"',
+ \ ' }',
+ \ ' ]',
+ \ ' }',
+ \ ' }',
+ \ '}',
+ \ ])
diff --git a/test/linter/test_npmgroovylit.vader b/test/linter/test_npmgroovylit.vader
new file mode 100644
index 00000000..25195861
--- /dev/null
+++ b/test/linter/test_npmgroovylit.vader
@@ -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'