Better phpstan default configuration (#2444)

* Use phpstan config file as default whenever possible + report as error
This commit is contained in:
Julien Deniau
2019-05-02 00:14:39 +02:00
committed by w0rp
parent 4c6f67a3d0
commit c6aae3bcfc
3 changed files with 58 additions and 17 deletions

View File

@@ -3,7 +3,7 @@
" 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')
let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '')
let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')
function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
@@ -12,14 +12,26 @@ function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
\ ? ' -c ' . l:configuration
\ : ''
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)
\ ? ' -l ' . l:level
\ : ''
let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
\ ? ' --error-format raw'
\ : ' --errorFormat raw'
return '%e analyze -l'
\ . ale#Var(a:buffer, 'php_phpstan_level')
return '%e analyze --no-progress'
\ . l:error_format
\ . l:configuration_option
\ . l:level_option
\ . ' %s'
endfunction
@@ -35,7 +47,7 @@ function! ale_linters#php#phpstan#Handle(buffer, lines) abort
call add(l:output, {
\ 'lnum': l:match[2] + 0,
\ 'text': l:match[3],
\ 'type': 'W',
\ 'type': 'E',
\})
endfor