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

Can't disable rule Underscore #3939

Open
alexjonser opened this issue Feb 7, 2024 · 3 comments
Open

Can't disable rule Underscore #3939

alexjonser opened this issue Feb 7, 2024 · 3 comments

Comments

@alexjonser
Copy link

alexjonser commented Feb 7, 2024

Hello,

we are using in our projects the "Doctrine Coding Standard". For some reasons we want to declarate private properties and methods with a leading underscore.

I don't get it what we are doing wrong to exclude the "PSR2.Classes.PropertyDeclaration.Underscore" and "PSR2.Classes.MethodDeclaration.Underscore" rules.

Here my ruleset

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="DYStandard" xsi:noNamespaceSchemaLocation="./Vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <description>The DY coding standard.</description>
    <ini name="memory_limit" value="512M"/>

    <arg name="basepath" value="."/>
    <arg name="extensions" value="php"/>
    <arg name="parallel" value="80"/>
    <arg name="cache" value=".phpcs-cache"/>
    <arg name="colors"/>

    <arg value="ps"/>
    <file>./Vendor/frameworks/lifework/src/Lifemeter/Helper/Tableobject.php</file>

    <!-- Include full Doctrine Coding Standard -->
    <rule ref="Doctrine">
        <exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedName"/>
        <exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
        <exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidCommentType"/>
        <exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>
        <exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
        <exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
        <exclude name="PSR2.Classes.MethodDeclaration.Underscore" />
    </rule>

    <rule ref="Squiz.NamingConventions.ValidVariableName">
        <exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore" />
    </rule>

    <rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
        <properties>
            <property name="allowFallbackGlobalConstants" value="true"/>
        </properties>
    </rule>

PHPCS Output

54 | ERROR   | [ ] Private member variable "pDate" must contain a leading underscore (Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore)
   55 | WARNING | [ ] Property name "$_startDate" should not be prefixed with an underscore to indicate visibility (PSR2.Classes.PropertyDeclaration.Underscore)

Versions (please complete the following information)

Operating System Mac OS Ventura 13.2.1
PHP version 8.2.7
PHP_CodeSniffer version PHP_CodeSniffer version 3.8.1 (stable) by Squiz and PHPCSStandards
Standard Doctrine / Custom
Install type composer
@alexjonser
Copy link
Author

in addition there is following error in my phpcs output

1 | ERROR   | [ ] An error occurred during processing; checking has been aborted. The error message was: "else" without curly braces is not supported.
      |         |     The error originated in the SlevomatCodingStandard.ControlStructures.EarlyExit sniff on line 401. (Internal.Exception)

@alexjonser
Copy link
Author

example out of my composer.json

"config" : {
    "vendor-dir" : "Vendor",
    "allow-plugins": {
      "dealerdirect/phpcodesniffer-composer-installer": true
    }
  },
  "require-dev": {
    "doctrine/coding-standard" : "*"
  }

@jrfnl
Copy link
Contributor

jrfnl commented May 19, 2024

Please don't open issues in this repo anymore. This repo is abandoned and https://github.com/PHPCSStandards/PHP_CodeSniffer is its successor. See: #3932

If the original issue is is still an issue, please open a ticket in the new repo and include a PHP code sample to reproduce the behaviour.

One thing I can already see is a typo:

- <exclude name="PSR2.Classes.MethodDeclaration.Underscore" />
+ <exclude name="PSR2.Methods.MethodDeclaration.Underscore" />

As for the error coming from the Slevomat standard: that's not a PHPCS issue, but an issue with the Slevomat standard in combination with your code and the error spells out what is needed to fix it: ""else" without curly braces is not supported."

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