PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Ignore error based on message

Open Luc45 opened this issue 3 years ago • 2 comments

I'd like to enforce comments on every class method with Squiz.Commenting.FunctionComment.Missing, except if the function is a __construct.

I'm not seeing a way to accomplish, as the I can either enable/disable this rule globally in the application or for some specific files, but not for the __construct function specifically.

To accomplish this, I wanted to ignore an error based on the message I receive, similar to how PHPStan does it:

<rule ref="Squiz.Commenting.FunctionComment.Missing">
    <exclude-message>#^Missing doc comment for function __construct\(\)$#</exclude-message>
</rule>

Is it currently possible to achieve this in PHPCS? If not, this issue is a feature suggestion to add this functionality, as it gives a lot of flexibility to the rules.

Thank you for your time.

PS: I have seen https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#squizcommentingfunctioncomment but it does not do what I want.

PS 2: I wouldn't want to add inline ignores for every __construct

Luc45 avatar Mar 28 '22 16:03 Luc45

This is not currently possible with PHPCS.

Generally speaking, either allowing a sniff to be customized via properties or a sniff having (very) modular error codes, which would allow to exclude a specific error code is the way to do this in PHPCS.

jrfnl avatar Mar 28 '22 18:03 jrfnl

Yeah same! need this! or only be able to exclude certain functions like __construct for the rule

tijmenmoddit avatar Nov 03 '23 19:11 tijmenmoddit