Better phpstan default configuration (#2444)
* Use phpstan config file as default whenever possible + report as error
This commit is contained in:
parent
4c6f67a3d0
commit
c6aae3bcfc
3 changed files with 58 additions and 17 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
" Set to change the ruleset
|
" Set to change the ruleset
|
||||||
let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpstan')
|
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', '')
|
let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '')
|
||||||
|
|
||||||
function! ale_linters#php#phpstan#GetCommand(buffer, version) abort
|
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
|
\ ? ' -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])
|
let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
|
||||||
\ ? ' --error-format raw'
|
\ ? ' --error-format raw'
|
||||||
\ : ' --errorFormat raw'
|
\ : ' --errorFormat raw'
|
||||||
|
|
||||||
return '%e analyze -l'
|
return '%e analyze --no-progress'
|
||||||
\ . ale#Var(a:buffer, 'php_phpstan_level')
|
|
||||||
\ . l:error_format
|
\ . l:error_format
|
||||||
\ . l:configuration_option
|
\ . l:configuration_option
|
||||||
|
\ . l:level_option
|
||||||
\ . ' %s'
|
\ . ' %s'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -35,7 +47,7 @@ function! ale_linters#php#phpstan#Handle(buffer, lines) abort
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'lnum': l:match[2] + 0,
|
\ 'lnum': l:match[2] + 0,
|
||||||
\ 'text': l:match[3],
|
\ 'text': l:match[3],
|
||||||
\ 'type': 'W',
|
\ 'type': 'E',
|
||||||
\})
|
\})
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
|
|
@ -1,34 +1,66 @@
|
||||||
Before:
|
Before:
|
||||||
|
call delete('./phpstan.neon')
|
||||||
call ale#assert#SetUpLinterTest('php', 'phpstan')
|
call ale#assert#SetUpLinterTest('php', 'phpstan')
|
||||||
|
|
||||||
GivenCommandOutput ['0.10.2']
|
GivenCommandOutput ['0.10.2']
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
call delete('./phpstan.neon')
|
||||||
call ale#assert#TearDownLinterTest()
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
Execute(Custom executables should be used for the executable and command):
|
Execute(Custom executables should be used for the executable and command):
|
||||||
let g:ale_php_phpstan_executable = 'phpstan_test'
|
let g:ale_php_phpstan_executable = 'phpstan_test'
|
||||||
|
|
||||||
AssertLinter 'phpstan_test',
|
AssertLinter 'phpstan_test',
|
||||||
\ ale#Escape('phpstan_test') . ' analyze -l4 --errorFormat raw %s'
|
\ ale#Escape('phpstan_test') . ' analyze --no-progress --errorFormat raw -l 4 %s'
|
||||||
|
|
||||||
Execute(project with level set to 3):
|
Execute(project with level set to 3):
|
||||||
call ale#test#SetFilename('phpstan-test-files/foo/test.php')
|
call ale#test#SetFilename('phpstan-test-files/foo/test.php')
|
||||||
let g:ale_php_phpstan_level = 3
|
let g:ale_php_phpstan_level = 3
|
||||||
|
|
||||||
AssertLinter 'phpstan',
|
AssertLinter 'phpstan',
|
||||||
\ ale#Escape('phpstan') . ' analyze -l3 --errorFormat raw %s'
|
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat raw -l 3 %s'
|
||||||
|
|
||||||
Execute(Custom phpstan configuration file):
|
Execute(Custom phpstan configuration file):
|
||||||
let g:ale_php_phpstan_configuration = 'phpstan_config'
|
let g:ale_php_phpstan_configuration = 'phpstan_config'
|
||||||
|
|
||||||
AssertLinter 'phpstan',
|
AssertLinter 'phpstan',
|
||||||
\ ale#Escape('phpstan') . ' analyze -l4 --errorFormat raw -c phpstan_config %s'
|
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat raw -c phpstan_config -l 4 %s'
|
||||||
|
|
||||||
Execute(Choose the right format for error format param):
|
Execute(Choose the right format for error format param):
|
||||||
GivenCommandOutput ['0.10.3']
|
GivenCommandOutput ['0.10.3']
|
||||||
|
|
||||||
AssertLinter 'phpstan', [
|
AssertLinter 'phpstan', [
|
||||||
\ ale#Escape('phpstan') . ' --version',
|
\ ale#Escape('phpstan') . ' --version',
|
||||||
\ ale#Escape('phpstan') . ' analyze -l4 --error-format raw %s'
|
\ ale#Escape('phpstan') . ' analyze --no-progress --error-format raw -l 4 %s'
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
Execute(Configuration file exists in current directory):
|
||||||
|
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
||||||
|
let g:ale_php_phpstan_level = ''
|
||||||
|
let g:ale_php_phpstan_configuration = ''
|
||||||
|
|
||||||
|
AssertLinter 'phpstan', [
|
||||||
|
\ ale#Escape('phpstan') . ' --version',
|
||||||
|
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat raw %s'
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
Execute(Configuration file exists in current directory, but force phpstan level):
|
||||||
|
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
||||||
|
let g:ale_php_phpstan_configuration = ''
|
||||||
|
let g:ale_php_phpstan_level = '7'
|
||||||
|
|
||||||
|
AssertLinter 'phpstan', [
|
||||||
|
\ ale#Escape('phpstan') . ' --version',
|
||||||
|
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat raw -l 7 %s'
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
Execute(Configuration file exists in current directory, but force phpstan configuration):
|
||||||
|
call writefile(['parameters:', ' level: 7'], './phpstan.neon')
|
||||||
|
let g:ale_php_phpstan_level = ''
|
||||||
|
let g:ale_php_phpstan_configuration = 'phpstan.custom.neon'
|
||||||
|
|
||||||
|
AssertLinter 'phpstan', [
|
||||||
|
\ ale#Escape('phpstan') . ' --version',
|
||||||
|
\ ale#Escape('phpstan') . ' analyze --no-progress --errorFormat raw -c phpstan.custom.neon %s'
|
||||||
\ ]
|
\ ]
|
||||||
|
|
|
@ -14,7 +14,7 @@ Execute(Output without errors should be parsed correctly):
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ [],
|
\ [],
|
||||||
\ ale_linters#php#phpstan#Handle(bufnr(''), [" 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%"])
|
\ ale_linters#php#phpstan#Handle(bufnr(''), [])
|
||||||
|
|
||||||
Execute(Output with some errors should be parsed correctly):
|
Execute(Output with some errors should be parsed correctly):
|
||||||
call ale#test#SetFilename('phpstan-test-files/foo/test.php')
|
call ale#test#SetFilename('phpstan-test-files/foo/test.php')
|
||||||
|
@ -24,21 +24,20 @@ Execute(Output with some errors should be parsed correctly):
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 9,
|
\ 'lnum': 9,
|
||||||
\ 'text': 'Call to method format() on an unknown class DateTimeImutable.',
|
\ 'text': 'Call to method format() on an unknown class DateTimeImutable.',
|
||||||
\ 'type': 'W'
|
\ 'type': 'E'
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 16,
|
\ 'lnum': 16,
|
||||||
\ 'text': 'Sample message.',
|
\ 'text': 'Sample message.',
|
||||||
\ 'type': 'W'
|
\ 'type': 'E'
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 192,
|
\ 'lnum': 192,
|
||||||
\ 'text': 'Invalid command testCommand.',
|
\ 'text': 'Invalid command testCommand.',
|
||||||
\ 'type': 'W'
|
\ 'type': 'E'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
||||||
\ ' 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%',
|
|
||||||
\ 'phpstan-test-files/foo/test.php:9:Call to method format() on an unknown class DateTimeImutable.',
|
\ 'phpstan-test-files/foo/test.php:9:Call to method format() on an unknown class DateTimeImutable.',
|
||||||
\ 'phpstan-test-files/foo/test.php:16:Sample message.',
|
\ 'phpstan-test-files/foo/test.php:16:Sample message.',
|
||||||
\ 'phpstan-test-files/foo/test.php:192:Invalid command testCommand.',
|
\ 'phpstan-test-files/foo/test.php:192:Invalid command testCommand.',
|
||||||
|
@ -52,11 +51,10 @@ Execute(Output should be parsed correctly with Windows paths):
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 9,
|
\ 'lnum': 9,
|
||||||
\ 'text': 'Access to an undefined property Test::$var.',
|
\ 'text': 'Access to an undefined property Test::$var.',
|
||||||
\ 'type': 'W'
|
\ 'type': 'E'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
||||||
\ ' 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%',
|
|
||||||
\ 'D:\phpstan-test-files\foo\test.php:9:Access to an undefined property Test::$var.',
|
\ 'D:\phpstan-test-files\foo\test.php:9:Access to an undefined property Test::$var.',
|
||||||
\])
|
\])
|
||||||
|
|
||||||
|
@ -68,10 +66,9 @@ Execute(Output for .inc files should be parsed correctly):
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 9,
|
\ 'lnum': 9,
|
||||||
\ 'text': 'Access to an undefined property Test::$var.',
|
\ 'text': 'Access to an undefined property Test::$var.',
|
||||||
\ 'type': 'W'
|
\ 'type': 'E'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
\ ale_linters#php#phpstan#Handle(bufnr(''), [
|
||||||
\ ' 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%',
|
|
||||||
\ '/phpstan-test-files/foo/test.inc:9:Access to an undefined property Test::$var.',
|
\ '/phpstan-test-files/foo/test.inc:9:Access to an undefined property Test::$var.',
|
||||||
\])
|
\])
|
||||||
|
|
Reference in a new issue