diff options
author | Albert Peschar <albert@peschar.net> | 2023-02-02 07:09:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 14:09:11 +0900 |
commit | 599f7b1eda20d48cf0a68c543b9e8d31266010eb (patch) | |
tree | b4309160f80b27237cdc03400d4d8358383d7100 /ale_linters | |
parent | 116d713f63c7a81663fa53efa10e34649c9479e3 (diff) | |
download | ale-599f7b1eda20d48cf0a68c543b9e8d31266010eb.zip |
phpstan: set cwd to configuration file directory (#4422)
PHPStan will only detect a configuration file in the current working
directory, so set that to the directory in which ALE finds the
configuration file.
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/php/phpstan.vim | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ale_linters/php/phpstan.vim b/ale_linters/php/phpstan.vim index 4dce5d5f..b0d2a8d3 100644 --- a/ale_linters/php/phpstan.vim +++ b/ale_linters/php/phpstan.vim @@ -26,10 +26,8 @@ function! ale_linters#php#phpstan#GetCommand(buffer, version) abort \ : '' let l:level = ale#Var(a:buffer, 'php_phpstan_level') - let l:config_file_exists = ale#path#FindNearestFile(a:buffer, 'phpstan.neon') - let l:dist_config_file_exists = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist') - if empty(l:level) && empty(l:config_file_exists) && empty(l:dist_config_file_exists) + if empty(l:level) && empty(ale_linters#php#phpstan#FindConfigFile(a:buffer)) " if no configuration file is found, then use 4 as a default level let l:level = '4' endif @@ -70,6 +68,22 @@ function! ale_linters#php#phpstan#Handle(buffer, lines) abort return l:output endfunction +function! ale_linters#php#phpstan#GetCwd(buffer) abort + let l:result = ale#path#Dirname(ale_linters#php#phpstan#FindConfigFile(a:buffer)) + + return empty(l:result) ? v:null : l:result +endfunction + +function! ale_linters#php#phpstan#FindConfigFile(buffer) abort + let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon') + + if empty(l:result) + let l:result = ale#path#FindNearestFile(a:buffer, 'phpstan.neon.dist') + endif + + return l:result +endfunction + call ale#linter#Define('php', { \ 'name': 'phpstan', \ 'executable': {buffer -> ale#path#FindExecutable(buffer, 'php_phpstan', [ @@ -86,4 +100,5 @@ call ale#linter#Define('php', { \ function('ale_linters#php#phpstan#GetCommand'), \ )}, \ 'callback': 'ale_linters#php#phpstan#Handle', +\ 'cwd': function('ale_linters#php#phpstan#GetCwd'), \}) |