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
@fredden Thanks for opening this issue. I agree this is confusing, but I don't think the functionality is incorrectly handled - phpcs-onlyis being respected.
I think the issue is more a UI one and that a phpcs run should not mark an error/warning as fixable (via the X) when the standard/category/sniff/error code was flagged to be phpcs-only.
Been thinking about this one some more now that I've studied the Ruleset class more closely while writing the tests.
The problem is that with the current architecture, the Ruleset is deterministic. What I mean by that is that it only contains the end-result of the rules in the XML file(s), not the decision information which determined what the end-result should look like.
Or to put it in more practical terms: the Ruleset doesn't store whether a sniff was loaded because it had the phpcs-only flag set.
Additionally, the shouldProcessElement() method used to determine whether to process a rule is agnostic to the XML element on which it is used and, again, is deterministic (bool return value).
The only way I can think of to solve the issue described above, would be to introduce logic to determine for rule elements (only) whether the phpcs-only attribute is being applied AND PHPCS is in CS mode and then to store those sniff codes/error codes in a new (private) property with a getter method which can be passed an error code and can then check if that error code aligns with any of the stored "CS mode only" codes.
This getter could then be called in the File::addMessage() and update the $fixable flag before it is used in the method.
I discussed this somewhat with @jrfnl on a call today. It would be good to understand how these two attributes are used in the wild, as there may be scope for removing them completely if they aren't being used, or replacing them with something more suited to the use-cases identified. Next steps for this would be to do a search of public code using these attributes, and understand why they were introduced to PHP_CodeSniffer in the first place.
Describe the bug
When using the
phpcs-only
orphpcbf-only
attributes within a ruleset, the reports fromphpcs
do not look as expected.Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above.phpcs.xml
with the custom ruleset above.phpcs
phpcbf
phpcs
andphpcbf
regarding "fixable" error.Expected behaviour
The errors reported by
phpcs
as fixable should be fixed byphpcbf
.Versions (please complete the following information)
master
branch at time of writing)master
branch)Additional context
There are some words describing how the
phpcs-only
andphpcbf-only
attributes should work here: https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset#selectively-applying-rulesPlease confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: