Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the java PMD linter #1488

Merged
merged 1 commit into from Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 |
Expand Down
36 changes: 36 additions & 0 deletions 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',
\})
14 changes: 14 additions & 0 deletions doc/ale-java.txt
Expand Up @@ -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:
3 changes: 2 additions & 1 deletion doc/ale.txt
Expand Up @@ -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|
Expand Down Expand Up @@ -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`
Expand Down
27 changes: 27 additions & 0 deletions 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"'
\ ])