-
-
Notifications
You must be signed in to change notification settings - Fork 867
-
-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce feature flag for extension-installer #11714
Comments
in our projects we also do some ugly 'dance' to enable/disable extensions in some cases. did you realize you can put extensions on a ignore list ? |
Yes but given that TwigStan runs within the project of the user, it won't make any difference. It would require people to disable the extension for normal PHPStan analysis as well. |
Hey, I thought about this but I think it's against your interests. PHPStan extensions are not just about extra rules. They are also about making analysis smarter (more precise type inference). I think that Twigstan should include user's PHPStan config and just override some stuff it needs. Otherwise you're at risk collecting information from PHP code (controllers etc.) with dumber analysis than PHPStan is usually capable of when analysing the cobase. Because with the above in mind, you're now at risk of having some errors reported besides the things Twigstan itself reports (I mean the final CollectedDataNode rule that provides metadata to the error formatter), you should be a little bit more defensive and filter the errors reported by your own identifier. If you do that then there's basically no harm in extra rules being run while Twigstan is doing its job collecting data for further execution. |
Thanks. You're right, extensions have more benefits than just adding errors. I will try to support the extension-installer out of the box, and manually ignore the errors reported by phpstan-strict-rules. I can use this snippet to extract those identifiers (from time to time): curl -s https://raw.githubusercontent.com/phpstan/phpstan/2.0.x/website/src/errorsIdentifiers.json | jq -r '[ to_entries[] | select(.value | .[] | has("phpstan/phpstan-strict-rules")) | .key ] | unique[]' |
@ruudk You should allow-list only your known identifiers, not exclude errors from phpstan-strict-rules. You'll get many more errors reported by other extensions as well. |
It's not that simple. I want all errors to be reported. TwigStan does not have any custom errors at the moment. The compiled Twig templates are just PHP after all. This is perfectly fine Twig code: {{ user.id == object.id ? 'a' : 'b' }} But it produces this error:
This is because Twig is not as strict as PHP (can be). So the compiled code is also not as strict. Maybe I should just ignore these type of identifiers when I spot them. Instead of trying to ignore all identifiers from phpstan-strict-rules. |
I get it, I thought you were talking about the collector run, not the final "error run" 😊 |
Yes indeed. The collector run works great with: level: null
customRulesetUsed: true Now that the extension-installer is no longer disabled, this does give the type improvement, but does not produce any errors, only collected data. |
Feature request
Currently, PHPStan automatically tries to load
PHPStan\ExtensionInstaller\GeneratedConfig
via the autoloader. When it exists, it must be becausephpstan/extension-installer
was installed. This works great.Except for when you want to run PHPStan conditionally, without it picking up all extensions.
For example, in TwigStan I execute PHPStan to analyze compiled Twig templates. But there I don't want phpstan-strict-rules to be picked up automatically. Especially since compiled Twig templates don't follow these strict rules. If it was only used on my project, I could have turned off the extension-installer and went for a manual approach. But since this will be used by others as well, they most likely will be using the extension-installer.
Can we introduce a feature flag, that's enabled by default, but can be turned off when needed? I can create the PR obviously.
Currently I deal with it in a very naive way:
https://github.com/twigstan/twigstan/blob/a5a746a4bec2c735ff1fc2dbbf6feb8d877f0f6c/src/Application/AnalyzeCommand.php#L303-L307
https://github.com/twigstan/twigstan/blob/a5a746a4bec2c735ff1fc2dbbf6feb8d877f0f6c/src/Application/AnalyzeCommand.php#L379-L383
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: