2017-07-16 10:04:25 -04:00
|
|
|
" Author: medains <https://github.com/medains>, ardis <https://github.com/ardisdreelath>
|
|
|
|
" Description: phpstan for PHP files
|
|
|
|
|
|
|
|
" Set to change the ruleset
|
|
|
|
let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpstan')
|
|
|
|
let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '4')
|
|
|
|
|
2017-08-21 13:42:18 -04:00
|
|
|
function! ale_linters#php#phpstan#GetExecutable(buffer) abort
|
2017-07-16 10:04:25 -04:00
|
|
|
return ale#Var(a:buffer, 'php_phpstan_executable')
|
2017-08-21 13:42:18 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#php#phpstan#GetCommand(buffer) abort
|
|
|
|
let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer)
|
|
|
|
|
|
|
|
return ale#Escape(l:executable)
|
2017-07-16 10:04:25 -04:00
|
|
|
\ . ' analyze -l'
|
|
|
|
\ . ale#Var(a:buffer, 'php_phpstan_level')
|
|
|
|
\ . ' --errorFormat raw'
|
|
|
|
\ . ' %s'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#php#phpstan#Handle(buffer, lines) abort
|
|
|
|
" Matches against lines like the following:
|
|
|
|
"
|
|
|
|
" filename.php:15:message
|
|
|
|
" C:\folder\filename.php:15:message
|
|
|
|
let l:pattern = '^\([a-zA-Z]:\)\?[^:]\+:\(\d\+\):\(.*\)$'
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'text': l:match[3],
|
|
|
|
\ 'type': 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'phpstan',
|
2017-08-21 13:42:18 -04:00
|
|
|
\ 'executable_callback': 'ale_linters#php#phpstan#GetExecutable',
|
2017-07-16 10:04:25 -04:00
|
|
|
\ 'command_callback': 'ale_linters#php#phpstan#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#php#phpstan#Handle',
|
|
|
|
\})
|