2017-07-16 14:04:25 +00: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')
|
2019-05-01 22:14:39 +00:00
|
|
|
let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '')
|
2017-09-30 16:18:20 +00:00
|
|
|
let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')
|
2017-07-16 14:04:25 +00:00
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
|
2017-09-30 16:18:20 +00:00
|
|
|
let l:configuration = ale#Var(a:buffer, 'php_phpstan_configuration')
|
|
|
|
let l:configuration_option = !empty(l:configuration)
|
2019-05-07 18:38:32 +00:00
|
|
|
\ ? ' -c ' . ale#Escape(l:configuration)
|
2017-09-30 16:18:20 +00:00
|
|
|
\ : ''
|
|
|
|
|
2019-05-01 22:14:39 +00:00
|
|
|
let l:level = ale#Var(a:buffer, 'php_phpstan_level')
|
|
|
|
let l:config_file_exists = ale#path#FindNearestFile(a:buffer, 'phpstan.neon')
|
|
|
|
|
|
|
|
if empty(l:level) && empty(l:config_file_exists)
|
|
|
|
" if no configuration file is found, then use 4 as a default level
|
|
|
|
let l:level = '4'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:level_option = !empty(l:level)
|
2019-05-07 18:38:32 +00:00
|
|
|
\ ? ' -l ' . ale#Escape(l:level)
|
2019-05-01 22:14:39 +00:00
|
|
|
\ : ''
|
|
|
|
|
2019-04-07 13:58:06 +00:00
|
|
|
let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
|
2018-11-23 09:39:50 +00:00
|
|
|
\ ? ' --error-format raw'
|
|
|
|
\ : ' --errorFormat raw'
|
|
|
|
|
2019-05-01 22:14:39 +00:00
|
|
|
return '%e analyze --no-progress'
|
2018-11-23 09:39:50 +00:00
|
|
|
\ . l:error_format
|
2017-09-30 16:18:20 +00:00
|
|
|
\ . l:configuration_option
|
2019-05-01 22:14:39 +00:00
|
|
|
\ . l:level_option
|
2017-07-16 14:04:25 +00:00
|
|
|
\ . ' %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],
|
2019-05-01 22:14:39 +00:00
|
|
|
\ 'type': 'E',
|
2017-07-16 14:04:25 +00:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('php', {
|
|
|
|
\ 'name': 'phpstan',
|
2019-04-07 13:58:06 +00:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'php_phpstan_executable')},
|
|
|
|
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
|
|
|
|
\ buffer,
|
|
|
|
\ ale#Var(buffer, 'php_phpstan_executable'),
|
|
|
|
\ '%e --version',
|
|
|
|
\ function('ale_linters#php#phpstan#GetCommand'),
|
|
|
|
\ )},
|
2017-07-16 14:04:25 +00:00
|
|
|
\ 'callback': 'ale_linters#php#phpstan#Handle',
|
|
|
|
\})
|