summaryrefslogtreecommitdiff
path: root/ale_linters/php/phan.vim
blob: f3b3d48fbfefae1fe8040f8f9f85a9b78a3de586 (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: diegoholiveira <https://github.com/diegoholiveira>
" Description: static analyzer for PHP

" Define the minimum severity
let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)

function! ale_linters#php#phan#GetCommand(buffer) abort
    return 'phan -y '
    \   . ale#Var(a:buffer, 'php_phan_minimum_severity')
    \   . ' %s'
endfunction

function! ale_linters#php#phan#Handle(buffer, lines) abort
    " Matches against lines like the following:
    "
    " /path/to/some-filename.php:18 ERRORTYPE message
    let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\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[3],
        \   'type': 'W',
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('php', {
\   'name': 'phan',
\   'executable': 'phan',
\   'command_callback': 'ale_linters#php#phan#GetCommand',
\   'callback': 'ale_linters#php#phan#Handle',
\})