ale icon indicating copy to clipboard operation
ale copied to clipboard

phpstan is called with "-l 4" instead of 0 in certain situations

Open cprn opened this issue 5 years ago • 4 comments

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

  1. Create PHP project without phpstan.neon file or with configuration in phpstan.neon.dist
  2. add let g:ale_php_phpstan_level = 0 in your ~/.vimrc
  3. 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>>>

cprn avatar Apr 27 '20 14:04 cprn

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.

leihog avatar Feb 08 '21 14:02 leihog

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)

hsanson avatar Feb 14 '21 14:02 hsanson

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?

rymdbar avatar Apr 01 '25 06:04 rymdbar

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).

cprn avatar Apr 27 '25 00:04 cprn