2018-05-08 05:19:47 +00:00
|
|
|
" Author: diegoholiveira <https://github.com/diegoholiveira>, haginaga
|
2017-10-24 21:25:02 +00:00
|
|
|
" Description: static analyzer for PHP
|
|
|
|
|
|
|
|
" Define the minimum severity
|
|
|
|
let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)
|
|
|
|
|
2018-05-08 05:19:47 +00:00
|
|
|
let g:ale_php_phan_executable = get(g:, 'ale_php_phan_executable', 'phan')
|
|
|
|
let g:ale_php_phan_use_client = get(g:, 'ale_php_phan_use_client', 0)
|
|
|
|
|
|
|
|
function! ale_linters#php#phan#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'php_phan_executable')
|
|
|
|
endfunction
|
|
|
|
|
2017-10-24 21:25:02 +00:00
|
|
|
function! ale_linters#php#phan#GetCommand(buffer) abort
|
2018-05-08 05:19:47 +00:00
|
|
|
let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
|
|
|
|
if l:use_client == 1
|
|
|
|
let l:args = '-l '
|
|
|
|
\ . ' %s'
|
|
|
|
else
|
|
|
|
let l:args = '-y '
|
|
|
|
\ . ale#Var(a:buffer, 'php_phan_minimum_severity')
|
|
|
|
\ . ' %s'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:executable = ale_linters#php#phan#GetExecutable(a:buffer)
|
|
|
|
|
|
|
|
return ale#Escape(l:executable) . ' ' . l:args
|
2017-10-24 21:25:02 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#php#phan#Handle(buffer, lines) abort
|
2018-05-08 05:19:47 +00:00
|
|
|
let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
|
|
|
|
|
2017-10-24 21:25:02 +00:00
|
|
|
" Matches against lines like the following:
|
2018-05-08 05:19:47 +00:00
|
|
|
if l:use_client == 1
|
|
|
|
" Phan error: ERRORTYPE: message in /path/to/some-filename.php on line nnn
|
|
|
|
let l:pattern = '^Phan error: \(\w\+\): \(.\+\) in \(.\+\) on line \(\d\+\)$'
|
|
|
|
else
|
|
|
|
" /path/to/some-filename.php:18 ERRORTYPE message
|
|
|
|
let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
|
|
|
|
endif
|
2017-10-24 21:25:02 +00:00
|
|
|
|
2018-05-08 05:19:47 +00:00
|
|
|
let l:output = []
|
2017-10-24 21:25:02 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2018-05-08 05:19:47 +00:00
|
|
|
if l:use_client == 1
|
|
|
|
let l:dict = {
|
|
|
|
\ 'lnum': l:match[4] + 0,
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'type': 'W',
|
|
|
|
\}
|
|
|
|
else
|
|
|
|
let l:dict = {
|
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'text': l:match[3],
|
|
|
|
\ 'type': 'W',
|
|
|
|
\}
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, l:dict)
|
2017-10-24 21:25:02 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'phan',
|
2018-05-08 05:19:47 +00:00
|
|
|
\ 'executable_callback': 'ale_linters#php#phan#GetExecutable',
|
2017-10-24 21:25:02 +00:00
|
|
|
\ 'command_callback': 'ale_linters#php#phan#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#php#phan#Handle',
|
|
|
|
\})
|