Add support for the java PMD linter
This commit is contained in:
		
							parent
							
								
									2f2dcb8444
								
							
						
					
					
						commit
						49c4bfde14
					
				@ -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 |
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								ale_linters/java/pmd.vim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								ale_linters/java/pmd.vim
									
									
									
									
									
										Normal file
									
								
							@ -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',
 | 
			
		||||
\})
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
@ -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`
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										27
									
								
								test/handler/test_pmd_handler.vader
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/handler/test_pmd_handler.vader
									
									
									
									
									
										Normal file
									
								
							@ -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"'
 | 
			
		||||
  \ ])
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user