SanderRonde / phpstan-vscode

PHPStan plugin for VSCode
https://marketplace.visualstudio.com/items?itemName=SanderRonde.phpstan-vscode
MIT License
43 stars 8 forks source link

Paths excluded in `phpstan.neon` `parameters.excludePaths` throw an error on save #41

Closed fritz-c closed 10 months ago

fritz-c commented 1 year ago

I have a phpstan.neon config file that looks more or less like the following:

includes:
    - ./vendor/nunomaduro/larastan/extension.neon

parameters:
    paths:
        - app
    level: 5
    excludePaths:
        - ./tests/*

and my VSCode config contains the following:

"phpstan.binCommand": [
    "docker-compose",
    "exec",
    "app",
    "vendor/bin/phpstan"
],
"phpstan.enableLanguageServer": false,
"phpstan.paths": {
    "/path/to/my-project": "/app"
}

The extension works perfectly for almost all files, but when I edit a file under tests/, I get the following error in the console, and a VSCode notification pops up:

[check:160] Spawning PHPStan with the following configuration:  {"binCmd":"docker-compose","args":["exec","app","vendor/bin/phpstan","analyse","-c","/app/phpstan.neon","--error-format=raw","--no-interaction","--memory-limit=1G","--no-progress","/app/tests/Feature/MyFeatureTest.php"]}
[check:160] PHPStan process exited with error  filteredErr=! [NOTE] No files found to analyse.
[WARNING] This will cause a non-zero exit code in PHPStan 2.0.  rawErr=
 ! [NOTE] No files found to analyse.                                            

 [WARNING] This will cause a non-zero exit code in PHPStan 2.0.                 

  data=
[check:160] Check completed for file:///path/to/my-project/tests/Feature/MyFeatureTest.php errors= {}
image

It appears that the phpstan.neon config is being read in properly, but calling phpstan with a file it has explicitly been told to ignore results in 0 files being checked and that results in an error.

SanderRonde commented 1 year ago

Is this unexpected behavior? From this comment by the creator of PHPStan it appears to be intentional.

fritz-c commented 1 year ago

I believe it is the expected behavior for phpstan. Using that configuration in combination with your extension, however, I couldn't find any way to avoid the repeated appearance of the error notification when I had the extension configured to lint the current file every time I save.

SanderRonde commented 1 year ago

Ah never mind this is indeed the fault of the extension. It's triggering checks on files that it shouldn't check. Will fix when I've got some time.

fritz-c commented 1 year ago

Sounds good, thanks for looking into it.

I figured out a fix for myself in the meantime, of using path properties on ignoreErrors entries in the phpstan.neon file instead of excludePaths.

SanderRonde commented 1 year ago

I think I got a fix for this issue. Would you mind testing it for me? I've attached the .vsix (VSCode extension installer) file as a .zip file since github doesn't allow uploading of .vsix files. Could you:

Thanks in advance!

phpstan-vscode-2.2.24.zip

github-actions[bot] commented 10 months ago

Issues go stale after too much time without activity. If inactive for another 7 days this issue will be closed.

SanderRonde commented 9 months ago

Looked into this some more, this should be automatically fixed when moving to project-wide checking. That is currently active in the pre-release version of the extension.