summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Wienke <languitar@semipol.de>2018-04-09 17:45:08 +0200
committerJohannes Wienke <languitar@semipol.de>2018-04-09 17:48:00 +0200
commit49c4bfde148dfb4925c79a2e93eb04311afcc904 (patch)
tree55a216f1543e2c3b003bfd8c9ddb80902b89908d
parent2f2dcb84444f440ceb4b35010b861738216525f6 (diff)
downloadale-49c4bfde148dfb4925c79a2e93eb04311afcc904.zip
Add support for the java PMD linter
-rw-r--r--README.md2
-rw-r--r--ale_linters/java/pmd.vim36
-rw-r--r--doc/ale-java.txt14
-rw-r--r--doc/ale.txt3
-rw-r--r--test/handler/test_pmd_handler.vader27
5 files changed, 80 insertions, 2 deletions
diff --git a/README.md b/README.md
index 5f06d945..887af08a 100644
--- a/README.md
+++ b/README.md
@@ -112,7 +112,7 @@ formatting.
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) |
| HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) |
| Idris | [idris](http://www.idris-lang.org/) |
-| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format) |
+| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) |
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) |
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions |
diff --git a/ale_linters/java/pmd.vim b/ale_linters/java/pmd.vim
new file mode 100644
index 00000000..d461e094
--- /dev/null
+++ b/ale_linters/java/pmd.vim
@@ -0,0 +1,36 @@
+" Author: Johannes Wienke <languitar@semipol.de>
+" Description: PMD for Java files
+
+function! ale_linters#java#pmd#Handle(buffer, lines) abort
+ let l:pattern = '"\(\d\+\)",".\+","\(.\+\)","\(\d\+\)","\(\d\+\)","\(.\+\)","\(.\+\)","\(.\+\)"$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'type': 'W',
+ \ 'lnum': l:match[4] + 0,
+ \ 'text': l:match[5],
+ \ 'code': l:match[6] . ' - ' . l:match[7],
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+function! ale_linters#java#pmd#GetCommand(buffer) abort
+ return 'pmd '
+ \ . ale#Var(a:buffer, 'java_pmd_options')
+ \ . ' -f csv'
+ \ . ' -d %t'
+endfunction
+
+if !exists('g:ale_java_pmd_options')
+ let g:ale_java_pmd_options = '-R category/java/bestpractices.xml'
+endif
+
+call ale#linter#Define('java', {
+\ 'name': 'pmd',
+\ 'executable': 'pmd',
+\ 'command_callback': 'ale_linters#java#pmd#GetCommand',
+\ 'callback': 'ale_linters#java#pmd#Handle',
+\})
diff --git a/doc/ale-java.txt b/doc/ale-java.txt
index 3837f6c6..4481e823 100644
--- a/doc/ale-java.txt
+++ b/doc/ale-java.txt
@@ -61,5 +61,19 @@ g:ale_java_google_java_format_options *g:ale_java_google_java_format_options*
This variable can be set to pass additional options
+
+===============================================================================
+pmd *ale-java-pmd*
+
+g:ale_java_pmd_options *g:ale_java_pmd_options*
+ *b:ale_java_pmd_options*
+
+ Type: String
+ Default: '-R category/java/bestpractices'
+
+ This variable can be changed to modify flags given to PMD. Do not specify -f
+ and -d. They are added automatically.
+
+
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale.txt b/doc/ale.txt
index 0d3053e2..3f4a4299 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -106,6 +106,7 @@ CONTENTS *ale-contents*
checkstyle..........................|ale-java-checkstyle|
javac...............................|ale-java-javac|
google-java-format..................|ale-java-google-java-format|
+ pmd.................................|ale-java-pmd|
javascript............................|ale-javascript-options|
eslint..............................|ale-javascript-eslint|
flow................................|ale-javascript-flow|
@@ -343,7 +344,7 @@ Notes:
* Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`
* HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good`
* Idris: `idris`
-* Java: `checkstyle`, `javac`, `google-java-format`
+* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo`
* JSON: `fixjson`, `jsonlint`, `jq`, `prettier`
* Kotlin: `kotlinc`, `ktlint`
diff --git a/test/handler/test_pmd_handler.vader b/test/handler/test_pmd_handler.vader
new file mode 100644
index 00000000..0c95fb2a
--- /dev/null
+++ b/test/handler/test_pmd_handler.vader
@@ -0,0 +1,27 @@
+Before:
+ runtime ale_linters/java/pmd.vim
+
+After:
+ call ale#linter#Reset()
+
+Execute(The pmd handler should parse lines correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 18,
+ \ 'text': 'Each class should declare at least one constructor',
+ \ 'code': 'Code Style - AtLeastOneConstructor',
+ \ 'type': 'W',
+ \ },
+ \ {
+ \ 'lnum': 36,
+ \ 'text': 'Local variable ''node'' could be declared final',
+ \ 'code': 'Code Style - LocalVariableCouldBeFinal',
+ \ 'type': 'W',
+ \ },
+ \ ],
+ \ ale_linters#java#pmd#Handle(666, [
+ \ '"Problem","Package","File","Priority","Line","Description","Rule set","Rule"',
+ \ '"1","rsb.performance.test.ros","/home/languitar/src/rsb-performance-test-api-ros/src/main/java/rsb/performance/test/ros/NodeHolder.java","3","18","Each class should declare at least one constructor","Code Style","AtLeastOneConstructor"',
+ \ '"2","rsb.performance.test.ros","/home/languitar/src/rsb-performance-test-api-ros/src/main/java/rsb/performance/test/ros/NodeHolder.java","1","36","Local variable ''node'' could be declared final","Code Style","LocalVariableCouldBeFinal"'
+ \ ])