All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: Devon Meunier <devon.meunier@gmail.com>
2 " Description: checkstyle for Java files
4 call ale#Set('java_checkstyle_executable', 'checkstyle')
5 call ale#Set('java_checkstyle_config', '/google_checks.xml')
6 call ale#Set('java_checkstyle_options', '')
8 function! ale_linters#java#checkstyle#Handle(buffer, lines) abort
11 " modern checkstyle versions
12 let l:pattern = '\v\[(WARN|ERROR)\] [a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.*) \[(.+)\]'
14 for l:match in ale#util#GetMatches(a:lines, l:pattern)
16 \ 'type': l:match[1] is? 'WARN' ? 'W' : 'E',
17 \ 'sub_type': 'style',
18 \ 'lnum': l:match[2] + 0,
19 \ 'col': l:match[3] + 0,
29 " old checkstyle versions
30 let l:pattern = '\v(.+):(\d+): ([^:]+): (.+)$'
32 for l:match in ale#util#GetMatches(a:lines, l:pattern)
34 \ 'type': l:match[3] is? 'warning' ? 'W' : 'E',
35 \ 'sub_type': 'style',
36 \ 'lnum': l:match[2] + 0,
44 function! s:GetConfig(buffer, config) abort
45 if ale#path#IsAbsolute(a:config)
49 let s:file = ale#path#FindNearestFile(a:buffer, a:config)
51 return !empty(s:file) ? s:file : a:config
54 function! ale_linters#java#checkstyle#GetCommand(buffer) abort
55 let l:options = ale#Var(a:buffer, 'java_checkstyle_options')
56 let l:config_option = ale#Var(a:buffer, 'java_checkstyle_config')
57 let l:config = l:options !~# '\v(^| )-c ' && !empty(l:config_option)
58 \ ? s:GetConfig(a:buffer, l:config_option)
62 \ . ale#Pad(l:options)
63 \ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
67 call ale#linter#Define('java', {
68 \ 'name': 'checkstyle',
69 \ 'executable': {b -> ale#Var(b, 'java_checkstyle_executable')},
70 \ 'command': function('ale_linters#java#checkstyle#GetCommand'),
71 \ 'callback': 'ale_linters#java#checkstyle#Handle',