Repository navigation
Ignoring multiple rules using phpcs:ignore only ignores the first one since version 4.0.0 #1277
Copy link
Copy link
Closed
Description
Describe the bug
Ignoring multiple rules using phpcs:ignore only ignores the first one since version 4.0.0
Code sample
<?php
final class CustomSessionHandler extends SessionHandler {
// phpcs:ignore Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function create_sid(): string {
return 'example';
}
}
?>Custom ruleset
<?xml version="1.0"?>
<ruleset name="Custom Standard" namespace="CS\Standard">
<description>A custom coding standard</description>
<arg name="tab-width" value="2" />
<rule ref="Generic">
<exclude name="Generic.Arrays.ArrayIndent.KeyIncorrect" />
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Generic.Commenting" />
<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
<exclude name="Generic.Files.EndFileNoNewline.Found" />
<exclude name="Generic.Files.InlineHTML.Found" />
<exclude name="Generic.Files.LineLength" />
<exclude name="Generic.Files.LowercasedFilename.NotFound" />
<exclude name="Generic.Formatting" />
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine" />
<exclude name="Generic.Metrics.CyclomaticComplexity" />
<exclude name="Generic.PHP.RequireStrictTypes.MissingDeclaration" />
<exclude name="Generic.PHP.UpperCaseConstant.Found" />
<exclude name="Generic.Strings.UnnecessaryStringConcat.Found" />
<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing.SpaceAfterOpen" />
<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing.SpaceBeforeClose" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
</rule>
<rule ref="PSR12">
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.LineIndent" />
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter" />
<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakIndent" />
<exclude name="PSR2.Files.ClosingTag.NotAllowed" />
<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.Indent" />
</rule>
</ruleset>
To reproduce
Steps to reproduce the behavior:
- Create a file with the code sample above
- Run phpcs with the given ruleset
- See the error message for a rule that should be ignored
----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------
5 | ERROR | Method name "CustomSessionHandler::create_sid" is not in camel caps format (PSR1.Methods.CamelCapsMethodName.NotCamelCaps)
----------------------------------------------------------------------------------------------------------------------------------------
Expected behavior
As was the case in 3.x.x both rules should be ignored.
Versions
| Operating System | Linux 6.8.0-83-generic |
| PHP version | 8.3.6 |
| PHP_CodeSniffer version | 4.0.0 |
| Standard | custom |
| Install type | Composer (local) |
Additional context
No additional context.
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
4.xbranch of PHP_CodeSniffer.
Reactions are currently unavailable
Activity
jrfnl commentedon Sep 20, 2025
@Domi04151309 Thanks for reporting this. I can reproduce the issue with the provided information (working on PHPCS 3.x, not working on 4.x).
Having said that, I'm not sure whether this should really be regarded as a bug in PHPCS as the syntax you are using in the
phpcs:ignoreis not a syntax which was ever officially supported.phpcs:ignore(and disable/enable) take a comma-separate list of codes to ignore. not a "comma space" separated list.So, changing the ignore statement to use valid syntax fixes the issue immediately (tested and confirmed):
Domi04151309 commentedon Sep 20, 2025
Thanks for the quick reply. Removing the space works for me but maybe this can be added to the release notes as an additional info in case other people accidentally used this unofficial syntax.
jrfnl commentedon Sep 20, 2025
I'm first going to quickly look into how easy it would be to bring this whitespace tolerance back. If the fix would be straight forward, expect a PR. If it would turn out to be complicated to fix, I'll add something to the upgrade guides.
For now, bear with me.
For the record: I believe this was broken in #123
jrfnl commentedon Sep 21, 2025
@Domi04151309 If you have a chance, could you test PR #1278 ?
jrfnl commentedon Nov 10, 2025
@Domi04151309 Sorry it took a while, but the fix for this has now been released in the PHPCS 4.0.1 release,