You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
4.0 | Formally stop support for sniffs not complying with the PHPCS naming conventions #689
While PHPCS currently has partial/limited support for sniff file includes of sniffs which do not comply with the PHPCS naming conventions (as outlined in the Coding Standard Tutorial), AFAICS this is more by accident than by design and I propose to formally drop support for this in PHPCS 4.0.
If/when code is discovered which explicitly supports unconventional setups, remove that code (and any related tests; or possibly: change the tests to confirm this is not supported).
Note: this task does not have to be completed for the 4.0 release and code covered by this task can be removed at any point in time after the 4.0 release, as long as the 4.0 task 1 (explicit mention in release notes and upgrade guide) has been executed.
No longer accept any bug reports/feature requests related to sniffs which do not comply with the PHPCS naming conventions and close those immediately and without hesitation.
Other than that, I think it would be good to review the text of the Coding Standard Tutorial and to clarify the expected naming conventions where needed.
Note: including sniffs by file name will still be supported, but the sniffs included MUST be in a directory structure and with a namespace and class name which comply with the PHPCS naming conventions.
Does PHPCS have a deprecation mechanism that could be leveraged to make people aware of this in 3.x, and to migrate ahead of time? Maybe that could reduce the number of reports filed.
Does PHPCS have a deprecation mechanism that could be leveraged to make people aware of this in 3.x, and to migrate ahead of time? Maybe that could reduce the number of reports filed.
Good point. PHPCS doesn't have a deprecation mechanism for this, but I think this can probably be detected when loading the ruleset, which would mean we could throw a deprecation notice without impacting CS runs.
I'm going to look into this.
Reacted by Grégoire Paris, Tomas Norre Mikkelsen and PiOliver
Yes to the plan, but I'd also like to see a code change which detects sniffs which do not confirm and refuses to load these into a ruleset, with a user-visible notice ideally.
Just FYI: I am working on adding an "error handling" mechanism to the Ruleset to allow for throwing such deprecation notices (and the warning @fredden mentions once we get to 4.0).
Principles I'm working from:
Classify "errors" as "blocking" (like no sniffs being registered) or "non-blocking" (like an incorrect <type> being passed).
Don't hide one error behind another (if it can be avoided).
In practice this will come down to all errors being collected while the ruleset(s) are being processed and then at the end of the processing:
First display non-blocking issues (deprecations, notices, warnings).
Next display blocking errors.
If there are no blocking errors: continue the scan run.
Non-blocking errors will not affect the exit code and not be displayed in -q (quiet) mode.
Blocking errors will result in exit code 3 (as before).
The above will also be applied to the pre-existing errors being thrown from the Ruleset class.
The "problem" I'm running into is that the Ruleset class has relatively low code coverage and a lot of the pre-existing errors are not covered by tests.
In other words, I'm currently writing a sh*tload of tests to improve the code coverage of the Ruleset class. I expect to pull a lot of these over the next week or two.
After that I can introduce the new error handling in v 3.12.0 and possibly combine it straight away with a deprecation notice for the type of setups being discussed in this issue.
How does that sound ?
Reacted by Dan Wallis, Denis Žoljom and mk-mxp
Reacted by Grégoire Paris, Gary Jones and Payton Swick
We have been struggling to adjust our custom sniff to the naming conventions, as we use no full featured coding standard with an XML, but directly include the class in the main configuration. Our struggle was due to these points:
The Coding Standard Tutorial contains all the steps required to setup a full featured coding standard, but has no instructions on our use case
The Annotated Ruleset only shows how to refer to the class file, but has no further details
I suggest the following changes to these places, now or when the naming conventions are enforced:
<!--
If you are including sniffs that are not installed, you can
reference the sniff class using an absolute or relative path
instead of using the sniff code.
-->
should become
<!--
If you are including sniffs that are not installed, you can
reference the sniff class using an absolute or relative path
instead of using the sniff code.
The path and class name must follow the naming conventions
outlined in the Coding Standard Tutorial. Do not add sniff
classes to your autoloading. See
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Coding-Standard-Tutorial
-->
@mk-mxp Oh, thank you, that's a nice actionlist for me to apply!
I'm going to wait with updating the Wiki until I've finished the branch for this change locally (to see if I find anything else which should be included or is subtly different), but this will definitely come in very handy!
FYI: I'm nearly finished with all the work on the Ruleset class. Turned out that writing those tests was quite a lot of work 😉.
Once PR #801 has been merged, I can pull the changes as outlined in my comment above #689 (comment)
So... I've now also spend some time on the wiki and have added a new page "About Standards for PHP_CodeSniffer" which includes detailed information and examples about the naming conventions (and more).
Links to the new page have been added in the Annotated Ruleset and the Coding Standard Tutorial pages.
I'd love for you all to have a read through the new page. Feedback and improvements to the page are very welcome.
Reacted by mk-mxp, Gary Jones, William Desportes, Tomas Norre Mikkelsen and Rodrigo Primo
I'm not familiar with wiki pages, but if it's the same as for regular markdown file, I'd enable syntactic coloration with the syntax that consists in following the triple backticks with php
Also, I don't think invalid examples are useful given how clear the rest of the pages already is, they could even be confusing if somebody reads too fast and decides to use copy/paste from the wrong section.
Very impressive piece of documentation! And the Annotated Ruleset got a link to the naming conventions, too. Thanks a lot for your work!
I also like the invalid examples and don't think they do any harm. There is lots of valid copy&paste sources directly above those. Often it's easier to see your own faulty decisions in a negative example compared to mentally diffing against valid code.
I've kept the invalid examples for now, but have added a ❌ in front of the description for each, which should hopefully lessen the chance that people copy an invalid code sample.
Activity
greg0ire commentedon Nov 15, 2024
Does PHPCS have a deprecation mechanism that could be leveraged to make people aware of this in 3.x, and to migrate ahead of time? Maybe that could reduce the number of reports filed.
dingo-d commentedon Nov 15, 2024
A deprecation notice would be great and would definitely urge the external standards maintainers to fix this ahead of time.
jrfnl commentedon Nov 15, 2024
Good point. PHPCS doesn't have a deprecation mechanism for this, but I think this can probably be detected when loading the ruleset, which would mean we could throw a deprecation notice without impacting CS runs.
I'm going to look into this.
fredden commentedon Nov 17, 2024
Yes to the plan, but I'd also like to see a code change which detects sniffs which do not confirm and refuses to load these into a ruleset, with a user-visible notice ideally.
jrfnl commentedon Nov 18, 2024
Just FYI: I am working on adding an "error handling" mechanism to the
Rulesetto allow for throwing such deprecation notices (and the warning @fredden mentions once we get to 4.0).Principles I'm working from:
<type>being passed).In practice this will come down to all errors being collected while the ruleset(s) are being processed and then at the end of the processing:
Non-blocking errors will not affect the exit code and not be displayed in
-q(quiet) mode.Blocking errors will result in exit code
3(as before).The above will also be applied to the pre-existing errors being thrown from the
Rulesetclass.The "problem" I'm running into is that the
Rulesetclass has relatively low code coverage and a lot of the pre-existing errors are not covered by tests.In other words, I'm currently writing a sh*tload of tests to improve the code coverage of the
Rulesetclass. I expect to pull a lot of these over the next week or two.After that I can introduce the new error handling in v 3.12.0 and possibly combine it straight away with a deprecation notice for the type of setups being discussed in this issue.
How does that sound ?
greg0ire commentedon Nov 18, 2024
Sounds like a great improvement!
mk-mxp commentedon Nov 19, 2024
We have been struggling to adjust our custom sniff to the naming conventions, as we use no full featured coding standard with an XML, but directly include the class in the main configuration. Our struggle was due to these points:
I suggest the following changes to these places, now or when the naming conventions are enforced:
Annotated Ruleset
should become
Coding Standard Tutorial
I suggest adding a heading
Naming conventionsthat can be linked to directly. As far as I remember, the conventions are:{any prefix}/{Coding standard name}/Sniffs/{Category}/{SniffName}Sniff.php[{any prefix}\]{Coding standard name}\Sniffs\{Category}\{SniffName}{Coding standard name}.{Category}.{SniffName}to use in rulesets.,/or\allowed in{Coding standard name},{Category}and{SniffName}{Coding standard name},{Category}and{SniffName}you likecomposer-provided) autoloading, PHP_CodeSniffer handles class loading on its ownSuch a summarized specification of the naming convention would be enough, I think.
Edit: Added hints on autoloading.
jrfnl commentedon Nov 19, 2024
@mk-mxp Oh, thank you, that's a nice actionlist for me to apply!
I'm going to wait with updating the Wiki until I've finished the branch for this change locally (to see if I find anything else which should be included or is subtly different), but this will definitely come in very handy!
jrfnl commentedon Feb 5, 2025
FYI: I'm nearly finished with all the work on the Ruleset class. Turned out that writing those tests was quite a lot of work 😉.
Once PR #801 has been merged, I can pull the changes as outlined in my comment above #689 (comment)
So... I've now also spend some time on the wiki and have added a new page "About Standards for PHP_CodeSniffer" which includes detailed information and examples about the naming conventions (and more).
Links to the new page have been added in the Annotated Ruleset and the Coding Standard Tutorial pages.
I'd love for you all to have a read through the new page. Feedback and improvements to the page are very welcome.
greg0ire commentedon Feb 5, 2025
Very clear wiki page!
I think there are possibly some small fixes:
build-in => built-in
end on => end with
I'm not familiar with wiki pages, but if it's the same as for regular markdown file, I'd enable syntactic coloration with the syntax that consists in following the triple backticks with
phpAlso, I don't think invalid examples are useful given how clear the rest of the pages already is, they could even be confusing if somebody reads too fast and decides to use copy/paste from the wrong section.
mk-mxp commentedon Feb 5, 2025
Very impressive piece of documentation! And the Annotated Ruleset got a link to the naming conventions, too. Thanks a lot for your work!
I also like the invalid examples and don't think they do any harm. There is lots of valid copy&paste sources directly above those. Often it's easier to see your own faulty decisions in a negative example compared to mentally diffing against valid code.
jrfnl commentedon Feb 5, 2025
@greg0ire @mk-mxp Thank you both for reviewing and for your feedback.
I've made the following updates to the page now:
jrfnl commentedon Feb 7, 2025
Made one more update to the page:
jrfnl commentedon Mar 6, 2025
The changes outlined in comment #689 (comment) have (finally) been pulled...: #857
I'd really appreciate a critical look at that PR and welcome reviews.
jrfnl commentedon Mar 18, 2025
FYI: PR #892 is now open to add the deprecation notice.