diff options
author | lfree <xh.dreamlover@gmail.com> | 2018-11-23 17:39:50 +0800 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2018-11-23 09:39:50 +0000 |
commit | 2ab64514d02576b929ce3e7123fc45b6a148891a (patch) | |
tree | 4b748060974ea4d1d7c282b4c64059d63deb57bc /ale_linters/php | |
parent | ff0bd14efe8ba55594afe5175f562254d5268689 (diff) | |
download | ale-2ab64514d02576b929ce3e7123fc45b6a148891a.zip |
php: change phpstan's --errorFormat to --error-format (#2005)
* php: change phpstan's --errorFormat to --error-format
* add version check to phpstan
Diffstat (limited to 'ale_linters/php')
-rw-r--r-- | ale_linters/php/phpstan.vim | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/ale_linters/php/phpstan.vim b/ale_linters/php/phpstan.vim index b3875216..1c831e1b 100644 --- a/ale_linters/php/phpstan.vim +++ b/ale_linters/php/phpstan.vim @@ -6,15 +6,40 @@ let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpsta let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '4') let g:ale_php_phpstan_configuration = get(g:, 'ale_php_phpstan_configuration', '') -function! ale_linters#php#phpstan#GetCommand(buffer) abort +function! ale_linters#php#phpstan#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'php_phpstan_executable') +endfunction + +function! ale_linters#php#phpstan#VersionCheck(buffer) abort + let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer) + + " If we have previously stored the version number in a cache, then + " don't look it up again. + if ale#semver#HasVersion(l:executable) + " Returning an empty string skips this command. + return '' + endif + + let l:executable = ale#Escape(l:executable) + + return l:executable . ' --version' +endfunction + +function! ale_linters#php#phpstan#GetCommand(buffer, version_output) abort let l:configuration = ale#Var(a:buffer, 'php_phpstan_configuration') let l:configuration_option = !empty(l:configuration) \ ? ' -c ' . l:configuration \ : '' + let l:executable = ale_linters#php#phpstan#GetExecutable(a:buffer) + let l:version = ale#semver#GetVersion(l:executable, a:version_output) + let l:error_format = ale#semver#GTE(l:version, [0, 10, 3]) + \ ? ' --error-format raw' + \ : ' --errorFormat raw' + return '%e analyze -l' \ . ale#Var(a:buffer, 'php_phpstan_level') - \ . ' --errorFormat raw' + \ . l:error_format \ . l:configuration_option \ . ' %s' endfunction @@ -40,7 +65,10 @@ endfunction call ale#linter#Define('php', { \ 'name': 'phpstan', -\ 'executable_callback': ale#VarFunc('php_phpstan_executable'), -\ 'command_callback': 'ale_linters#php#phpstan#GetCommand', +\ 'executable_callback': 'ale_linters#php#phpstan#GetExecutable', +\ 'command_chain': [ +\ {'callback': 'ale_linters#php#phpstan#VersionCheck'}, +\ {'callback': 'ale_linters#php#phpstan#GetCommand'}, +\ ], \ 'callback': 'ale_linters#php#phpstan#Handle', \}) |