squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.63k stars 1.48k forks source link

PSR2.Methods.FunctionCallSignature.Indent cannot be exclude from command line #3920

Closed bhennesAdv closed 8 months ago

bhennesAdv commented 8 months ago

Describe the bug

The following rule is reported as an error from phpcs but cannot be excluded by the --exclude parameter : PSR2.Methods.FunctionCallSignature.Indent

Code sample

<?php
class TestClass
{
    public function testMethod(string $testParam): void
    {
        echo $testParam;
    }
};

$object = new TestClass();
$object->testMethod(
 'testParam1' //  <== Error is here
);

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
    <rule ref="PSR2.Methods.FunctionCallSignature.Indent">
        <severity>5</severity>
    </rule>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Create a file called custom-ruleset.xml with the ruleset sample above.
  3. Run phpcs test.php --standard=custom-ruleset.xml test.php -s
  4. See that the error is detected (So it's active and known) :
    
    FILE: /magento/test.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------
    12 | ERROR | [x] Multi-line function call not indented correctly; expected 4 spaces but found 1
    |       |     (PSR2.Methods.FunctionCallSignature.Indent)
    --------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------

Time: 10ms; Memory: 4MB

5. Run `phpcs --standard=custom-ruleset.xml test.php -s --exclude=PSR2.Methods.FunctionCallSignature.Indent`
6. See the error message below :
```bash
ERROR: The specified sniff code "PSR2.Methods.FunctionCallSignature.Indent" is invalid

Run "phpcs --help" for usage information

Expected behavior

The rule should be ignored and the output clean

Versions (please complete the following information)

Operating System Ubuntu 20.04
PHP version 7.4, 8.1 (both tested)
PHP_CodeSniffer version 3.3.1, 3.7.2 (both tested)
Standard PSR2
Install type composer, PHAR archive (both tested)

Additional context

Please confirm:

jrfnl commented 8 months ago

@bhennesAdv The --exclude parameter only takes sniff names, not error codes. This is documented behaviour, not a bug.

Also see https://github.com/squizlabs/PHP_CodeSniffer/issues/3895#issuecomment-1750235345

Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage

bhennesAdv commented 8 months ago

Hello,

Thank you, I had no idea about this difference. Sorry about that.