I wonder if it is possible to make PHPCS ignore one given rule for a particular file or line of code? Sometimes for different reasons I have to use // @codingStandardsIgnoreLine but this will make PHPCS completely ignore the line.
As a example, I would like to be able to do something like // @codingStandardsIgnoreLine Generic.WhiteSpace.ScopeIndent to make PHPCS ignore just indentation for the line. Is there a way to do that?
There is no way to do this using annotations in your files. See issue #604 for a feature request.
You can add exclusions for entire files using a ruleset.xml file. See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml for an example of hard-coding exclude patterns for specific sniffs. But you cannot do this for individual lines.
Put this at the top of the file:
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
@systemovich this does not work for me in combination with slevomat, it will either remove the comment or keep complaining. No other solution than to remove it for me.
@iltar Not sure about the details of your issue, but...
php
<?php
/**
<ul>
<li>File description<br />
*</li>
<li>@tags</li>
<li>@<a href="phpcs:disable">phpcs:disable</a> Standard.Cat.SniffName<br />
*/<br />
@jrfnl That seems to work, thanks!
Now we just need the ability to do it at the class and method level
Most helpful comment
@iltar Not sure about the details of your issue, but...
php <?php /** <ul> <li>File description<br /> *</li> <li>@tags</li> <li>@<a href="phpcs:disable">phpcs:disable</a> Standard.Cat.SniffName<br /> */<br />```xml