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

Render error identifier when ran verbose #15

Conversation

SanderMuller
Copy link
Contributor

PHPStan when ran verbose (-v) displays the error identifier. This is very useful when solving errors or choosing to ignore this type of error, either globally or locally

Global ignore example

In phpstan.neon

    ignoreErrors:
        - identifier: identical.alwaysFalse
          path: src/ErrorFormatter

Local ignore example

// @phpstan-ignore identical.alwaysFalse
if ('a' === 'b') {
    // test
}

Currently Simplify does not support rendering the error identifier, which is what keeps me from fully using it. This PR adds support for rendering the error identifier.

Example output:
vendor/bin/phpstan analyse --error-format symplify -v

 14/14 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec

 --------------------------------------------------------------------------------------------------------
  src/ErrorFormatter/SymplifyErrorFormatter.php:143
 --------------------------------------------------------------------------------------------------------
  - '#Strict comparison using \=\=\= between 'a' and 'b' will always evaluate to false#'
  🪪 identical.alwaysFalse
 --------------------------------------------------------------------------------------------------------


                                                                                                                
 [ERROR] Found 1 errors                                                                                                                                  

vendor/bin/phpstan analyse --error-format symplify (without the -v verbose flag) has no changes.

For reference, the PHPStan error formatter output with the -v verbose flag:

vendor/bin/phpstan analyse -v

 14/14 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec

 ------ -------------------------------------------------------------------------------- 
  Line   src/ErrorFormatter/SymplifyErrorFormatter.php                                   
 ------ -------------------------------------------------------------------------------- 
  143    Strict comparison using === between 'a' and 'b' will always evaluate to false.  
         🪪  identical.alwaysFalse                                                       
 ------ -------------------------------------------------------------------------------- 


                                                                                                                
 [ERROR] Found 1 error                                                                                          

@TomasVotruba
Copy link
Member

Thanks @SanderMuller , I've wanted this for a long time 👏

I've just approve the CI... could you check it?

@SanderMuller
Copy link
Contributor Author

Thanks @SanderMuller , I've wanted this for a long time 👏

I've just approve the CI... could you check it?

Thanks! I fixed PHPStan. Seems my test broke it. Shame the base getAnalysisResult doesnt work since it doesn't support adding an identifier, maybe my next PR to PHPStan haha

@SanderMuller
Copy link
Contributor Author

Thanks @SanderMuller , I've wanted this for a long time 👏
I've just approve the CI... could you check it?

Thanks! I fixed PHPStan. Seems my test broke it. Shame the base getAnalysisResult doesnt work since it doesn't support adding an identifier, maybe my next PR to PHPStan haha

The 6th error in the base class actually has an identifier, so used that one now @TomasVotruba

@TomasVotruba
Copy link
Member

vendor/bin/phpstan analyse -v

I'm curious... does PHPStan native error formatter display identifier also only with -v?

@TomasVotruba
Copy link
Member

Re-approved, these is new CI feedback 👍

@SanderMuller
Copy link
Contributor Author

vendor/bin/phpstan analyse -v

I'm curious... does PHPStan native error formatter display identifier also only with -v?

Yes

@SanderMuller
Copy link
Contributor Author

Re-approved, these is new CI feedback 👍

Tests were passing on Windows, will fix it from my Mac in a bit. 😅

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 7, 2025

@SanderMuller Don't worry about testing this, it's pretty straighforward :)

I've run classic PHPStan and it displays the identifier out of the box, even without -v. I think this one should have the same behavior:

Screenshot From 2025-01-07 08-08-01

@SanderMuller
Copy link
Contributor Author

@SanderMuller Don't worry about testing this, it's pretty straighforward :)

I've run classic PHPStan and it displays the identifier out of the box, even without -v. I think this one should have the same behavior:

Screenshot From 2025-01-07 08-08-01

I guess PHPStan 2.0 added this by default instead of opt-in. I think identifiers became mandatory in v2 and therefor making sense that it's rendered by default.
Updated this PR to render the identifier by default instead of only when verbose and removed the verbose tests

@TomasVotruba
Copy link
Member

Awesome, let's ship this 🙏

@TomasVotruba TomasVotruba merged commit 0ebe8c3 into symplify:main Jan 7, 2025
6 checks passed
@TomasVotruba
Copy link
Member

Thank you 👍

@TomasVotruba
Copy link
Member

Just tagged... give it a try: https://github.com/symplify/phpstan-extensions/releases/tag/12.0.1

@SanderMuller
Copy link
Contributor Author

Just tagged... give it a try: https://github.com/symplify/phpstan-extensions/releases/tag/12.0.1

Yay, it works how I want it to work! Thanks for the quick review, merge & tag!

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

Successfully merging this pull request may close these issues.

2 participants