-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
fix(ScopeKeywordSpacing): Check spaces after final keyword #604
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @klausi, thanks for this PR!
While in principle I agree with this change, the change you've made does more than "it says on the box".
Previously, the sniff checked the spacing after visibility keywords, static
and readonly
.
Now, it will also check final
and abstract
.
So this PR is not just an addition of final
, but also of abstract
to the tokens which are being checked.
I think, originally, the sniff was only intended for method and property prefixes.
And even though abstract
and final
could be used on methods, they were not included in the sniff as they would also affect class declarations.
Checking of scope keywords for anonymous functions snuck in with the introduction of static
closures in PHP 5.4 and then for arrow functions in PHP 7.4
Checking of scope keywords for class constant sort of snuck in with the introduction of constant visibility in PHP 7.1 (and final constants in PHP 8.1 if this change is accepted).
And the introduction of the readonly
keyword for properties being handled in PHP 8.1, had a side-effect that as of PHP 8.2, the readonly
keyword would also be checked for class declarations.
So, to come back to the proposed change in this PR. While it would now formally widen the scope of the sniff from "methods and properties" to "methods, properties, class constants and class declaration", I don't think that's a bad thing, so I have no objections against this PR.
I do, however, think that this means more tests are needed.
- Tests with
final
andabstract
on class declarations. - Tests with
final
on class constant declarations.
And if adding extra tests anyway, there should probably also be tests with the visibility keywords and class constants. And tests for static
arrow functions also look to be missing.
Note: these last two test additions would not be a blocker for this PR, but would still need to be done anyhow, either in this PR or in a follow-up PR.
Given these keywords can be used in more than one context, perhaps we should be producing more than one error code (ie, one per context, possibly also one per keyword?). We currently only throw To avoid a significant breaking change, we should endeavour to maintain the existing code for the intended/existing behaviour, and add a new code for new contexts (ie, class declaration). So, perhaps keep |
@klausi Just checking in. It would be great to include this change in the 3.11.0 release if it is ready in time. Will you have a chance to finish off the work on this ? |
Hi, currently swamped with other work, so it could take some time until I can check back. Feel free to take over or postpone it for a future release! |
Hi @klausi Thanks for letting me know. I understand, just wanted to prevent this PR from being forgotten as it is definitely a good candidate for merge. Pretty swamped myself atm, so take your time and we'll touch base again in a while ;-) |
@klausi Just wanted to check if you'll have time to finish this off soonish ? |
Hey there, still busy with other work so don't have time to follow-up here. Sorry! |
Sorry for the delay, now finally updated with more test cases. @jrfnl : I did the minimum you asked for, keeping this change in scope for the @fredden I don't think this will be a controversial breaking change. The class declaration context was already checked with the Currently we only emit one error code, so nobody has configured that to be silent. That is good, so we could introduce new error codes without them being breaking changes. I need to check if that is easy to do. |
The spacing after the
final
keyword should be checked by ScopeKeywordSpacingSniff.Description
This should throw an error because there are 6 spaces after
final
:Suggested changelog entry
Fixed bug XYZ : Squiz.WhiteSpace.ScopeKeywordSpacing detect white space problems after
final
keyword.Related issues/external references
Fir reported at Drupal's coder: https://www.drupal.org/project/coder/issues/3468410
Types of changes
Bug fix
PR checklist