How to override a rule/sniff in a PHP CodeSniffer ruleset correctly and to avoid doublechecking of code?
Excluding of a single sniff is easy done with the exclude
direction, e.g.:
<?xml version="1.0"?><ruleset name="ZF"> <description>...</description> <!-- Include the whole PSR-2 standard --> <rule ref="PSR2"> <!-- to disable a single error --> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction"/> <!-- or to disable the whole sniff --> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration"/> </rule> ...</ruleset>
instead of
<?xml version="1.0"?><ruleset name="ZF"> <description>...</description> <!-- Include the whole PSR-2 standard --> <rule ref="PSR2"/> ...</ruleset>
Overriding = Excluding of a sniff + Creating of an alternative one.
See also the annotated sample ruleset.xml
in the PHP CodeSniffer manual.