summaryrefslogtreecommitdiff
path: root/ale_linters/java/checkstyle.vim
blob: 8155170a2108e53dbd6513f1d1466e8701d7b7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
" Author: Devon Meunier <devon.meunier@gmail.com>
" 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 = []

    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

    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',
\})