1
0
Fork 0
mirror of synced 2024-11-05 00:48:57 -05:00
ultimate-vim/sources_non_forked/ale/ale_linters/java/checkstyle.vim

72 lines
2.1 KiB
VimL
Raw Normal View History

" Author: Devon Meunier <devon.meunier@gmail.com>
" Description: checkstyle for Java files
2019-08-22 11:36:17 -04:00
call ale#Set('java_checkstyle_executable', 'checkstyle')
call ale#Set('java_checkstyle_config', '/google_checks.xml')
call ale#Set('java_checkstyle_options', '')
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+)?:? (.*) \[(.+)\]$'
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-08-22 11:36:17 -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
return l:output
endfunction
2019-08-22 11:36:17 -04:00
function! s:GetConfig(buffer, config) abort
if ale#path#IsAbsolute(a:config)
return a:config
endif
let s:file = ale#path#FindNearestFile(a:buffer, a:config)
return !empty(s:file) ? s:file : a:config
endfunction
function! ale_linters#java#checkstyle#GetCommand(buffer) abort
2019-08-22 11:36:17 -04:00
let l:options = ale#Var(a:buffer, 'java_checkstyle_options')
let l:config_option = ale#Var(a:buffer, 'java_checkstyle_config')
let l:config = l:options !~# '\v(^| )-c' && !empty(l:config_option)
\ ? s:GetConfig(a:buffer, l:config_option)
\ : ''
return '%e'
\ . ale#Pad(l:options)
\ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
2018-12-17 06:28:27 -05:00
\ . ' %s'
endfunction
call ale#linter#Define('java', {
\ 'name': 'checkstyle',
2019-08-22 11:36:17 -04:00
\ 'executable': {b -> ale#Var(b, 'java_checkstyle_executable')},
2019-03-08 06:04:56 -05:00
\ 'command': function('ale_linters#java#checkstyle#GetCommand'),
\ 'callback': 'ale_linters#java#checkstyle#Handle',
2018-12-17 06:28:27 -05:00
\ 'lint_file': 1,
\})