-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PHPCS annotations: selective re-enabling not working as expected #1986
Comments
That looks right to me too, which wasn't the intention. |
Getting this working: // phpcs:disable PEAR,Squiz.Arrays
$foo = [1,2,3];
bar( $foo, true );
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar( $foo, true );
// phpcs:enable Squiz
$foo = [1,2,3];
// phpcs:enable Is going to be pretty hard using the current system. It only maintains a list of sniffs that are currently disabled, which allows you to re-enable a superset of sniffs (just remove entires from the list) but not a subset or a specific sniff, like in this case. I think this will require a second whitelist to be created and used during the adding of messages, which is't ideal but I can't think of another way right now. Will think more though, and try and few things. |
@gsherwood Yes, the only thing I could come up with while I was investigating this, was actually breaking the codes used in the "selection" down to the individual parts and setting it off against the sniffs included via the ruleset. |
I've committed a change to get this working. I ended up having to use an exception list, but I worked that into the current ignoredLines member var and did my best not to use it unless needed. I also renamed the existing I'll leave this open in case you have some time to test. |
@gsherwood Thanks for the quick turn-around on this one. Tests are mostly looking good, though I found one weird bug. Given this example code: // phpcs:disable PEAR
bar( $foo, true );
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar( $foo, true );
// phpcs:disable PEAR.Functions.FunctionCallSignature
bar( $foo, true );
// phpcs:enable
bar( $foo, true ); When running PHPCS over this snippet using
If I repeat this without the --ignore-annotations, I:
|
I totally missed that case (selectively re-enable a sniff, then disable it again) but the latest commit fixes that. Thanks so much for testing. |
@gsherwood Thank you. I'll try and run some more tests later. |
@gsherwood Ok, so I think I've found another one. 😕 // phpcs:disable PEAR.Functions
bar( $foo, true );
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar( $foo, true );
// phpcs:enable PEAR.Functions.ValidDefaultValue
bar( $foo, true );
// phpcs:enable PEAR
bar( $foo, true ); When running PHPCS over this snippet using
If I repeat this without the
|
Yep, I figured out what I stuffed up and have fixed that one up too. Thanks for testing (again)! 😄 |
Thanks Greg. I'm going to leave it for a bit now as my imagination has run out of possible tests I can run. |
Thanks again. I'll close as I think all the major cases are covered. |
Example code based on: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file with some small adjustments to test this properly:
When running PHPCS over this snippet using
phpcs -p -s ./test.php --standard=PEAR,Squiz --ignore-annotations
, I see the following errors (ignoring the filecomment related errors):If I repeat this without the
--ignore-annotations
, I only see the file comment errors, while I would expect to see:PEAR.Functions.FunctionCallSignature
errors on line 7Squiz.Arrays.ArrayDeclaration
error on line 9A cursory analysis gives me the impression that selective re-enabling only works when using the exact same "selection" as for the disabling, so:
... works as expected.
Using a higher/lower level Standard/Category/SniffName in the enable vs the disable command, seems to break the functionality which is in stark contrast to what the documentation suggests.
I've checked the above against various points in time between the
3.2.0
version and the currentmaster
, but it looks like this was never implemented as intended.The text was updated successfully, but these errors were encountered: