2018-06-14 06:31:12 -04:00
|
|
|
" Author: diegoholiveira <https://github.com/diegoholiveira>, haginaga <https://github.com/haginaga>
|
2018-03-31 10:55:20 -04: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-06-14 06:31:12 -04: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
|
|
|
|
let l:executable = ale#Var(a:buffer, 'php_phan_executable')
|
|
|
|
|
|
|
|
if ale#Var(a:buffer, 'php_phan_use_client') == 1 && l:executable is# 'phan'
|
|
|
|
let l:executable = 'phan_client'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return l:executable
|
|
|
|
endfunction
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
function! ale_linters#php#phan#GetCommand(buffer) abort
|
2018-06-14 06:31:12 -04:00
|
|
|
if ale#Var(a:buffer, 'php_phan_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
|
2018-03-31 10:55:20 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#php#phan#Handle(buffer, lines) abort
|
|
|
|
" Matches against lines like the following:
|
2018-06-14 06:31:12 -04:00
|
|
|
if ale#Var(a:buffer, 'php_phan_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
|
2021-06-30 13:00:07 -04:00
|
|
|
let l:pattern = '^\(.*\):\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
|
2018-06-14 06:31:12 -04:00
|
|
|
endif
|
|
|
|
|
2018-03-31 10:55:20 -04:00
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2018-06-14 06:31:12 -04:00
|
|
|
if ale#Var(a:buffer, 'php_phan_use_client') == 1
|
|
|
|
let l:dict = {
|
|
|
|
\ 'lnum': l:match[4] + 0,
|
|
|
|
\ 'text': l:match[2],
|
2021-06-30 13:00:07 -04:00
|
|
|
\ 'filename': l:match[3],
|
2018-06-14 06:31:12 -04:00
|
|
|
\ 'type': 'W',
|
|
|
|
\}
|
|
|
|
else
|
|
|
|
let l:dict = {
|
2021-06-30 13:00:07 -04:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'text': l:match[4],
|
2018-06-14 06:31:12 -04:00
|
|
|
\ 'type': 'W',
|
2021-06-30 13:00:07 -04:00
|
|
|
\ 'filename': l:match[1],
|
2018-06-14 06:31:12 -04:00
|
|
|
\}
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, l:dict)
|
2018-03-31 10:55:20 -04:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'phan',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': function('ale_linters#php#phan#GetExecutable'),
|
|
|
|
\ 'command': function('ale_linters#php#phan#GetCommand'),
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale_linters#php#phan#Handle',
|
|
|
|
\})
|