Skip to content

Commit 1d416db

Browse files
committed
Individual messages can now be excluded in ruleset.xml files using the exclude tag (request #20091)
1 parent 4af1311 commit 1d416db

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

CodeSniffer.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,23 @@ public function processRuleset($rulesetPath, $depth=0)
594594
echo "\t\tExcluding rule \"".$exclude['name'].'"'.PHP_EOL;
595595
}
596596

597-
$excludedSniffs = array_merge(
598-
$excludedSniffs,
599-
$this->_expandRulesetReference($exclude['name'], $rulesetDir, ($depth + 1))
600-
);
601-
}
602-
}
597+
// Check if a single code is being excluded, which is a shortcut
598+
// for setting the severity of the message to 0.
599+
$parts = explode('.', $exclude['name']);
600+
if (count($parts) === 4) {
601+
$this->ruleset[(string) $exclude['name']]['severity'] = 0;
602+
if (PHP_CODESNIFFER_VERBOSITY > 1) {
603+
echo str_repeat("\t", $depth);
604+
echo "\t\t=> severity set to 0".PHP_EOL;
605+
}
606+
} else {
607+
$excludedSniffs = array_merge(
608+
$excludedSniffs,
609+
$this->_expandRulesetReference($exclude['name'], $rulesetDir, ($depth + 1))
610+
);
611+
}
612+
}//end foreach
613+
}//end if
603614

604615
$this->_processRule($rule, $depth);
605616
}//end foreach

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
3232
- PSR2 standard now ignores comments when checking indentation rules
3333
- Generic UpperCaseConstantNameSniff no longer reports errors where constants are used (request #20090)
3434
-- It still reports errors where constants are defined
35+
- Individual messages can now be excluded in ruleset.xml files using the exclude tag (request #20091)
36+
-- Setting message severity to 0 continues to be supported
3537
- Fixed bug #20093 : Bug with ternary operator token
3638
- Fixed bug #20097 : CLI.php throws error in php 5.2
3739
- Fixed bug #20100 : incorrect Function mysql() has been deprecated report

0 commit comments

Comments
 (0)