summaryrefslogtreecommitdiff
path: root/ale_linters/php/phpmd.vim
blob: 9b1d1e445e43e432112a7ff0750b6edd77f509e1 (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
37
38
" Author: medains <https://github.com/medains>, David Sierra <https://github.com/davidsierradz>
" Description: phpmd for PHP files

let g:ale_php_phpmd_executable = get(g:, 'ale_php_phpmd_executable', 'phpmd')

" Set to change the ruleset
let g:ale_php_phpmd_ruleset = get(g:, 'ale_php_phpmd_ruleset', 'cleancode,codesize,controversial,design,naming,unusedcode')

function! ale_linters#php#phpmd#GetCommand(buffer) abort
    return '%e %s text'
    \   . ale#Pad(ale#Var(a:buffer, 'php_phpmd_ruleset'))
    \   . ' --ignore-violations-on-exit %t'
endfunction

function! ale_linters#php#phpmd#Handle(buffer, lines) abort
    " Matches against lines like the following:
    "
    " /path/to/some-filename.php:18 message
    let l:pattern = '^.*:\(\d\+\)\s\+\(.\+\)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        call add(l:output, {
        \   'lnum': l:match[1] + 0,
        \   'text': l:match[2],
        \   'type': 'W',
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('php', {
\   'name': 'phpmd',
\   'executable': {b -> ale#Var(b, 'php_phpmd_executable')},
\   'command': function('ale_linters#php#phpmd#GetCommand'),
\   'callback': 'ale_linters#php#phpmd#Handle',
\})