2018-03-31 10:55:20 -04:00
|
|
|
" Author: Devon Meunier <devon.meunier@gmail.com>
|
|
|
|
" Description: checkstyle for Java files
|
|
|
|
|
|
|
|
function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2018-12-17 06:28:27 -05:00
|
|
|
" modern checkstyle versions
|
|
|
|
let l:pattern = '\v\[(WARN|ERROR)\] [a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.*) \[(.+)\]$'
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'type': l:match[1] is? 'WARN' ? 'W' : 'E',
|
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
|
|
|
\ 'text': l:match[4],
|
|
|
|
\ 'code': l:match[5],
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
2019-05-31 14:39:36 -04:00
|
|
|
if !empty(l:output)
|
|
|
|
return l:output
|
|
|
|
endif
|
|
|
|
|
2018-12-17 06:28:27 -05:00
|
|
|
" 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
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
|
|
|
|
return 'checkstyle '
|
|
|
|
\ . ale#Var(a:buffer, 'java_checkstyle_options')
|
2018-12-17 06:28:27 -05:00
|
|
|
\ . ' %s'
|
2018-03-31 10:55:20 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
if !exists('g:ale_java_checkstyle_options')
|
|
|
|
let g:ale_java_checkstyle_options = '-c /google_checks.xml'
|
|
|
|
endif
|
|
|
|
|
|
|
|
call ale#linter#Define('java', {
|
|
|
|
\ 'name': 'checkstyle',
|
|
|
|
\ 'executable': 'checkstyle',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'command': function('ale_linters#java#checkstyle#GetCommand'),
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale_linters#java#checkstyle#Handle',
|
2018-12-17 06:28:27 -05:00
|
|
|
\ 'lint_file': 1,
|
2018-03-31 10:55:20 -04:00
|
|
|
\})
|