Skip to content
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

How to suppress UnusedPsalmSuppress? #6786

Closed
donquixote opened this issue Oct 31, 2021 · 11 comments
Closed

How to suppress UnusedPsalmSuppress? #6786

donquixote opened this issue Oct 31, 2021 · 11 comments

Comments

@donquixote
Copy link
Contributor

I have code that produces an inspection warning in PHP 7.4, but not in PHP 8.
I am using @psalm-suppress all to suppress in PHP 7.4, but now I get UnusedPsalmSuppress in PHP 8.

How can I suppress all of it?

@psalm-github-bot
Copy link

Hey @donquixote, can you reproduce the issue on https://psalm.dev ?

@donquixote
Copy link
Contributor Author

Hey @donquixote, can you reproduce the issue on https://psalm.dev ?

I don't think so. I cannot control the php version on psalm.dev.

@donquixote
Copy link
Contributor Author

To clarify, I am using the cli parameter --php-version=8.0 to switch version.

@weirdan
Copy link
Collaborator

weirdan commented Oct 31, 2021

I don't think so. I cannot control the php version on psalm.dev.

You can, by using ?php= query parameter. E.g. https://psalm.dev/r/e200b6c83e?php=7.1 vs https://psalm.dev/r/e200b6c83e?php=8.1

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/e200b6c83e
<?php
enum E {}
Psalm output (using commit 7f14d09):

ERROR: ParseError - 2:6 - Syntax error, unexpected T_STRING on line 2

ERROR: UndefinedConstant - 2:1 - Const enum is not defined
https://psalm.dev/r/e200b6c83e
<?php
enum E {}
Psalm output (using commit 7f14d09):

No issues!

@donquixote
Copy link
Contributor Author

I can't get psalm.dev to give me UnusedPsalmSuppress :(
At least the "RedundantCast" should be seen as redundant suppression.
Perhaps another query parameter? Are those documented somewhere?

@orklah
Copy link
Collaborator

orklah commented Oct 31, 2021

Not all config are available through psalm.dev. This one must be one of them.

To suppress UnusedPsalmSuppress, check this part of your config: https://psalm.dev/docs/running_psalm/configuration/#issuehandlers

@donquixote
Copy link
Contributor Author

I suppose this is to globally suppress UnusedPsalmSuppress?
I would like to do this locally, for a specific piece of code only.

@orklah
Copy link
Collaborator

orklah commented Oct 31, 2021

https://psalm.dev/docs/running_psalm/dealing_with_code_issues/ You can suppress it for a file or a directory

@orklah
Copy link
Collaborator

orklah commented Nov 1, 2021

I'm closing this because I'm afraid there's no simple better solution here.

The suppression module for this specific issue is complex. Issues may come from a lot of places inside Psalm, that's why UnusedPsalmSuppress has to be near the end of analysis and work its way through already emitted issues and check if every suppression has been used. However we're completely out of the analysis at that point and we have no way to access inlined suppression in the code anymore.

There may be grounds for improvements if we were to store this suppression from the start inside IssueBuffer and we'll welcome PR on this but we won't work on it. If someone wants to, a good place to start is by looking at IssueBuffer::addUnusedSuppression

@orklah orklah closed this as completed Nov 1, 2021
@orklah
Copy link
Collaborator

orklah commented Dec 11, 2021

Well, turns out @AndrolGenhald found a solution for this issue here: #7133. It will be available on next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants