From 5d6b4ef73f1d9532fe3f16cdbf5994aa6a3eb9fe Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Wed, 7 Nov 2018 13:25:48 +0100 Subject: Support older checkstyle versions The output format used by older checkstyle versions differs from the one of new versions. This commit adds a second parsing iteration on the output lines with a suitable pattern to support both versions in parallel. Due to the differences in the order of matching groups this is hard to achieve in a single pass through the output lines. An appropriate test case is added. --- ale_linters/java/checkstyle.vim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ale_linters/java') diff --git a/ale_linters/java/checkstyle.vim b/ale_linters/java/checkstyle.vim index 8155170a..7d0c31ba 100644 --- a/ale_linters/java/checkstyle.vim +++ b/ale_linters/java/checkstyle.vim @@ -2,9 +2,11 @@ " Description: checkstyle for Java files function! ale_linters#java#checkstyle#Handle(buffer, lines) abort - let l:pattern = '\v\[(WARN|ERROR)\] [a-zA-Z]?:?[^:]+:(\d+):(\d+)?:? (.*) \[(.+)\]$' 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) call add(l:output, { \ 'type': l:match[1] is? 'WARN' ? 'W' : 'E', @@ -15,6 +17,17 @@ function! ale_linters#java#checkstyle#Handle(buffer, lines) abort \}) 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 endfunction -- cgit v1.2.3 From 8e24a1a91658600771512e80c0c42c1ab1d6c117 Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Wed, 7 Nov 2018 13:26:54 +0100 Subject: Let checkstyle only lint original files Temporary files break checks like the one for a missing package-info.java, as discussed in #1305. --- ale_linters/java/checkstyle.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ale_linters/java') diff --git a/ale_linters/java/checkstyle.vim b/ale_linters/java/checkstyle.vim index 7d0c31ba..c07b65d0 100644 --- a/ale_linters/java/checkstyle.vim +++ b/ale_linters/java/checkstyle.vim @@ -34,7 +34,7 @@ endfunction function! ale_linters#java#checkstyle#GetCommand(buffer) abort return 'checkstyle ' \ . ale#Var(a:buffer, 'java_checkstyle_options') - \ . ' %t' + \ . ' %s' endfunction if !exists('g:ale_java_checkstyle_options') @@ -46,4 +46,5 @@ call ale#linter#Define('java', { \ 'executable': 'checkstyle', \ 'command_callback': 'ale_linters#java#checkstyle#GetCommand', \ 'callback': 'ale_linters#java#checkstyle#Handle', +\ 'lint_file': 1, \}) -- cgit v1.2.3