summaryrefslogtreecommitdiff
path: root/ale_linters/java/pmd.vim
blob: a1f4c93c16a77973dcec5f18873ece48b06e8065 (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: Johannes Wienke <languitar@semipol.de>
" Description: PMD for Java files

function! ale_linters#java#pmd#Handle(buffer, lines) abort
    let l:pattern = '"\(\d\+\)",".*","\(.\+\)","\(\d\+\)","\(\d\+\)","\(.\+\)","\(.\+\)","\(.\+\)"$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        call add(l:output, {
        \   'type': 'W',
        \   'lnum': l:match[4] + 0,
        \   'text': l:match[5],
        \   'code': l:match[6] . ' - ' . l:match[7],
        \})
    endfor

    return l:output
endfunction

function! ale_linters#java#pmd#GetCommand(buffer) abort
    return 'pmd '
    \ . ale#Var(a:buffer, 'java_pmd_options')
    \ . ' -f csv'
    \ . ' -d %t'
endfunction

if !exists('g:ale_java_pmd_options')
    let g:ale_java_pmd_options = '-R category/java/bestpractices.xml'
endif

call ale#linter#Define('java', {
\   'name': 'pmd',
\   'executable': 'pmd',
\   'command': function('ale_linters#java#pmd#GetCommand'),
\   'callback': 'ale_linters#java#pmd#Handle',
\})