I want to selectively disable one sniff in one file, which according to the docs should work with the phpcs:disable macro.
This is what I have at the top of my file:
<?php
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
Code Sniffer unfortunately still throws a warning for this sniff. I'm using version 3.2.3 via the phar package.
Disabling all sniffs for this file works:
<?php
// phpcs:disable
But that's not what I want.
Just checking: are you using \\ or // ? If \\, try //.
gah. sorry. I'm using // of course. I'll fix my comment.
You're not disabling a sniff what that comment - you're disabling a specific message from appearing from line 2 onwards. That error message is probably appearing on line 1.
But that's actually how all the error suppression sniffs work. You're not disabling the sniff from running - you are suppressing errors if they are reported on the lines after your comment.
But the SideEffects sniff has specific code in there to detect that you want it to ignore parts of the file when you use those comments. So what it does is check the file as if those lines didn't exist in it. But it only does this if you disable the sniff (or PHPCS itself) and not the individual message like you've done.
So in this case, I'd try using // phpcs:disable PSR1.Files.SideEffects.
Or you can ignore this specific file in your ruleset (if you have one) using an exclude pattern. I use one for PHPCS here: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist#L139
Does that help?
phpcs:disable PSR1.Files.SideEffects works for me.
It's still a bit weird to me because there should only be side effects after this (since there is no code before) but I guess that's how it is. Thanks for the hint.
It's still a bit weird to me because there should only be side effects after this
The sniff doesn't report an error for every side effect it finds. It reports a single error for the file, on line 1. The error suppression syntax tells PHPCS to suppress errors reported after that comment. But given the error is reported on line 1, it doesn't suppress it.
Had the same problem today. I was able to fix it by putting the error on the same line as the opening tag:
<?php // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
declare(strict_types=1);
// ....
Most helpful comment
phpcs:disable PSR1.Files.SideEffectsworks for me.It's still a bit weird to me because there should only be side effects after this (since there is no code before) but I guess that's how it is. Thanks for the hint.