Skip to content

Can't disable rule Underscore #3939

Open
@alexjonser

Description

@alexjonser

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions