Merge pull request #2063 from languitar/better-checkstyle
Checkstyle improvements
This commit is contained in:
commit
d30da203b9
@ -2,9 +2,11 @@
|
|||||||
" Description: checkstyle for Java files
|
" Description: checkstyle for Java files
|
||||||
|
|
||||||
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
||||||
let l:pattern = '\v\[(WARN|ERROR)\] [a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.*) \[(.+)\]$'
|
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
|
" modern checkstyle versions
|
||||||
|
let l:pattern = '\v\[(WARN|ERROR)\] [a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.*) \[(.+)\]$'
|
||||||
|
|
||||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'type': l:match[1] is? 'WARN' ? 'W' : 'E',
|
\ 'type': l:match[1] is? 'WARN' ? 'W' : 'E',
|
||||||
@ -15,13 +17,24 @@ function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
|||||||
\})
|
\})
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
" old checkstyle versions
|
||||||
|
let l:pattern = '\v(.+):(\d+): ([^:]+): (.+)$'
|
||||||
|
|
||||||
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
|
call add(l:output, {
|
||||||
|
\ 'type': l:match[3] is? 'warning' ? 'W' : 'E',
|
||||||
|
\ 'lnum': l:match[2] + 0,
|
||||||
|
\ 'text': l:match[4],
|
||||||
|
\})
|
||||||
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
||||||
return 'checkstyle '
|
return 'checkstyle '
|
||||||
\ . ale#Var(a:buffer, 'java_checkstyle_options')
|
\ . ale#Var(a:buffer, 'java_checkstyle_options')
|
||||||
\ . ' %t'
|
\ . ' %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if !exists('g:ale_java_checkstyle_options')
|
if !exists('g:ale_java_checkstyle_options')
|
||||||
@ -33,4 +46,5 @@ call ale#linter#Define('java', {
|
|||||||
\ 'executable': 'checkstyle',
|
\ 'executable': 'checkstyle',
|
||||||
\ 'command_callback': 'ale_linters#java#checkstyle#GetCommand',
|
\ 'command_callback': 'ale_linters#java#checkstyle#GetCommand',
|
||||||
\ 'callback': 'ale_linters#java#checkstyle#Handle',
|
\ 'callback': 'ale_linters#java#checkstyle#Handle',
|
||||||
|
\ 'lint_file': 1,
|
||||||
\})
|
\})
|
||||||
|
@ -26,3 +26,16 @@ Execute(The checkstyle handler should parse lines correctly):
|
|||||||
\ '[WARN] whatever:101: ''method def rcurly'' has incorrect indentation level 4, expected level should be 2. [Indentation]',
|
\ '[WARN] whatever:101: ''method def rcurly'' has incorrect indentation level 4, expected level should be 2. [Indentation]',
|
||||||
\ '[WARN] whatever:63:3: Missing a Javadoc comment. [JavadocMethod]',
|
\ '[WARN] whatever:63:3: Missing a Javadoc comment. [JavadocMethod]',
|
||||||
\ ])
|
\ ])
|
||||||
|
|
||||||
|
Execute(The checkstyle handler should parse lines from older checkstyle versions correctly):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 289,
|
||||||
|
\ 'text': '''method def modifier'' have incorrect indentation level 4, expected level should be 2.',
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale_linters#java#checkstyle#Handle(666, [
|
||||||
|
\ '/home/languitar/src/rsb-java/rsb-java/src/main/java/rsb/Listener.java:289: warning: ''method def modifier'' have incorrect indentation level 4, expected level should be 2.',
|
||||||
|
\ ])
|
||||||
|
Loading…
Reference in New Issue
Block a user