phpstan is called with "-l 4" instead of 0 in certain situations
Information
VIM version NVIM v0.5.0-dev Build type: RelWithDebInfo
Operating System: Linux, Ubuntu 18.04.4 LTS
What went wrong
Ale always runs PHPStan with -l 4 (level 4 of strictness) if php_phpstan_level =0 and there's no phpstan.neon file.
Reproducing the bug
- Create PHP project without
phpstan.neonfile or with configuration inphpstan.neon.dist - add
let g:ale_php_phpstan_level = 0in your~/.vimrc - run ALE and check ALEInfo
The issue is caused by these phpstan.vim lines:
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
If l:level is set to 0 above code empty(l:level) evaluates to true. If l:config_file_exists is empty as well the level value is always being set to 4.
I know nothing about vimscript but my guess is FindNearestFile should be only called if there's no explicit configuration path in g:ale_php_phpstan_configuration or that file doesn't exist (maybe), and when it's called it should look for both phpstan.neon and phpstan.neon.dist. Also there should be specific check for l:level == 0 because the result of empty(0) gives false positive.
:ALEInfo
(finished - exit code 1) ['/bin/bash', '-c', '''bin/phpstan'' analyze --no-progress --error-format raw -c ''phpstan.neon.dist'' -l ''4'' ''/home/cg/Projects/mailservice/src/MailService/MailShipment/Domain/Event/ShipmentWasCreated.php'' < '
'/tmp/nvimczCUv3/5/ShipmentWasCreated.php''']
<<<OUTPUT STARTS>>>
/home/cg/Projects/mailservice/src/MailService/MailShipment/Domain/Event/ShipmentWasCreated.php:14:Method MailService\MailShipment\Domain\Event\ShipmentWasCreated::new() should return MailService\MailShipment\Domain\Event\ShipmentWasCreated
but returns CG\EventSourcing\AggregateEvent.
<<<OUTPUT ENDS>>>
Using let g:ale_php_phpstan_level = '0' seems to work and I get the same issue regardless of the presence of a config file.
Maybe converting the l:level to string before checking for empty would make it work with string and number values:
if empty(string(l:level)) && empty(l:config_file_exists)
Did you @cprn ever have a chance to try out the suggestion about making level a string?
Would you be prepared to make transform it into a pull-request if it is a working fix?
Did you @cprn ever have a chance to try out the suggestion about making level a string? [...]
Nope. Sorry, Mate, but I don't work with PHP any more, and privately moved to Neovim + cmp & friends, so no more ALE for me (unless it's a liquid).