summaryrefslogtreecommitdiff
path: root/ale_linters/php/phpstan.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters/php/phpstan.vim')
-rw-r--r--ale_linters/php/phpstan.vim37
1 files changed, 9 insertions, 28 deletions
diff --git a/ale_linters/php/phpstan.vim b/ale_linters/php/phpstan.vim
index 34d4e799..ecd80a83 100644
--- a/ale_linters/php/phpstan.vim
+++ b/ale_linters/php/phpstan.vim
@@ -6,34 +6,13 @@ 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#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
+function! ale_linters#php#phpstan#GetCommand(buffer, version) 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])
+ let l:error_format = ale#semver#GTE(a:version, [0, 10, 3])
\ ? ' --error-format raw'
\ : ' --errorFormat raw'
@@ -65,10 +44,12 @@ endfunction
call ale#linter#Define('php', {
\ 'name': 'phpstan',
-\ 'executable': function('ale_linters#php#phpstan#GetExecutable'),
-\ 'command_chain': [
-\ {'callback': 'ale_linters#php#phpstan#VersionCheck'},
-\ {'callback': 'ale_linters#php#phpstan#GetCommand'},
-\ ],
+\ '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'),
+\ )},
\ 'callback': 'ale_linters#php#phpstan#Handle',
\})