-
-
Notifications
You must be signed in to change notification settings - Fork 88
Description
Follow up/repost from squizlabs/PHP_CodeSniffer#2823:
A number of sniffs contain a
public $errorproperty to toggle whether the sniff should throw anerroror awarning.This property has been superseded by the ability to specify
<type>error</type>for each sniff in a custom ruleset since PHPCS1.4.1.I'd like to suggest removing these
public $errorproperties from any sniffs which have them and to remove the code within theprocess()method of those sniffs handling the toggle.A quick scan yields the following sniffs for which this applies:
Generic.ControlStructures.InlineControlStructureGeneric.Formatting.MultipleStatementAlignmentGeneric.PHP.ForbiddenFunctionsGeneric.PHP.NoSilencedErrorsGeneric.Strings.UnnecessaryStringConcatSquiz.CSS.ForbiddenStyles(sniff will be removed anyway in 4.0.0)Squiz.PHP.DiscouragedFunctionsSquiz.PHP.ForbiddenFunctions(inherited)The Customizable Sniff Properties wiki page would also need to be updated for this change.
I'd suggest adding aRemoved incolumn (where relevant) to the properties table containing the version nr in which a property was removed.
@VincentLanglet left the following remark:
I do like this property when writing my own sniff extending for example
Generic.PHP.ForbiddenFunctions. It seems easier to modify the$errorproperty than overriding something in the ruleset.I think some Sniff made to be extendable could be better with a
protected $errorproperty.
An initial change related to this issue was already made for the 4.0 branch in commit squizlabs/PHP_CodeSniffer@606d876
With @gsherwood remarking:
I only ended up removing the property from 2 of the sniffs. The rest of the sniffs used the property to change messages or set a new default, as @VincentLanglet described in his comment.
The properties were removed from
Generic.Strings.UnnecessaryStringConcatandGeneric.Formatting.MultipleStatementAlignment
Upon which @jrfnl replied:
The rest of the sniffs used the property to change messages or set a new default
With the possible exception of the
ForbiddenFunctionssniff(s), I don't see why these properties would remain.Just like people can use
<type>in their ruleset to change something from anerrorto awarning, they can also adjust the<message>in the ruleset from "this is forbidden" to "this is discouraged", so there is no reason for the sniff to contain that logic.
That leaves the following actions to be executed:
- Remove the property from the
Generic.ControlStructures.InlineControlStructuresniff and review the error message. - Remove the property from the
Generic.PHP.NoSilencedErrorssniff and review the error message. - Change the
$errorproperty inGeneric.PHP.ForbiddenFunctionsfrompublictoprotected. - Change the property overload in the
Squiz.PHP.DiscouragedFunctions(inherited) frompublictoprotected. - Change the property overload in the
Squiz.PHP.ForbiddenFunctions(inherited) frompublictoprotected. - No change needed in the
Generic.PHP.DeprecatedFunctions, which also extends theGeneric.PHP.ForbiddenFunctionssniff, though the fact that that sniff is also impacted should be mentioned in the changelog.