Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bhennesAdv opened this issue Nov 9, 2023 · 2 comments

Comments

@bhennesAdv
Copy link

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
  1. Run phpcs --standard=custom-ruleset.xml test.php -s --exclude=PSR2.Methods.FunctionCallSignature.Indent
  2. See the error message below :
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:

  • [ X] I have searched the issue list and am not opening a duplicate issue.
  • [ X] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • [ X] I have verified the issue still exists in the master branch of PHP_CodeSniffer. (Last release tested, not tested from code)
@jrfnl
Copy link
Contributor

jrfnl commented Nov 9, 2023

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

Also see #3895 (comment)

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

@bhennesAdv
Copy link
Author

Hello,

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants