diff options
author | Devon Meunier <devon.meunier@shopify.com> | 2017-05-12 09:42:32 -0400 |
---|---|---|
committer | Devon Meunier <devon.meunier@shopify.com> | 2017-05-15 15:41:04 -0400 |
commit | 9baae52d1afab8af832c4249eefc19e7dd28a251 (patch) | |
tree | 09292c402445198082e350e919e9dbcfbee7d746 /ale_linters | |
parent | 07b2542c0d6505f2a843e700d246367a522ecf64 (diff) | |
download | ale-9baae52d1afab8af832c4249eefc19e7dd28a251.zip |
Add checkstyle linter
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/java/checkstyle.vim | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ale_linters/java/checkstyle.vim b/ale_linters/java/checkstyle.vim new file mode 100644 index 00000000..d3d48842 --- /dev/null +++ b/ale_linters/java/checkstyle.vim @@ -0,0 +1,46 @@ +" Author: Devon Meunier <devon.meunier@gmail.com> +" Description: checkstyle for Java files + +function! ale_linters#java#checkstyle#Handle(buffer, lines) abort + let l:patterns = [ + \ '\v\[(WARN|ERROR)\] .*:(\d+):(\d+): (.*)', + \ '\v\[(WARN|ERROR)\] .*:(\d+): (.*)', + \] + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:patterns) + let l:args = { + \ 'lnum': l:match[2] + 0, + \ 'type': l:match[1] =~? 'WARN' ? 'W' : 'E' + \ } + + let l:col = l:match[3] + 0 + if l:col > 0 + let l:args['col'] = l:col + let l:args['text'] = l:match[4] + else + let l:args['text'] = l:match[3] + endif + + call add(l:output, l:args) + endfor + + return l:output +endfunction + +function! ale_linters#java#checkstyle#GetCommand(buffer) abort + return 'checkstyle ' + \ . ale#Var(a:buffer, 'java_checkstyle_options') + \ . ' %t' +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', +\ 'command_callback': 'ale_linters#java#checkstyle#GetCommand', +\ 'callback': 'ale_linters#java#checkstyle#Handle', +\}) |