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.67k stars 1.48k forks source link

Enums still not supported as of 3.6.2 #3602

Closed jacekwilczynski closed 2 years ago

jacekwilczynski commented 2 years ago

Describe the bug Despite https://github.com/squizlabs/PHP_CodeSniffer/pull/3478, there's still Generic.WhiteSpace.ScopeIndent errors when using enums.

Code sample

<?php

declare(strict_types=1);

enum MyEnum
{
    case FIRST_OPTION;
    case SECOND_OPTION;
    case THIRD_OPTION;
}

Custom ruleset

<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <arg name="basepath" value="."/>
    <arg name="cache" value="var/.phpcs-cache"/>
    <arg name="colors"/>
    <arg name="extensions" value="php"/>
    <arg value="p"/>
    <arg value="n"/>
    <arg value="s"/>

    <rule ref="PSR1"/>

    <rule ref="PSR12">
        <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore"/>
        <exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter"/>
    </rule>

    <rule ref="Generic.Files.LineLength">
        <properties>
            <property name="lineLimit" value="120"/>
        </properties>
    </rule>
    <rule ref="Generic.Metrics.NestingLevel">
        <properties>
            <property name="nestingLevel" value="3"/>
            <property name="absoluteNestingLevel" value="3"/>
        </properties>
    </rule>
    <rule ref="Generic.PHP.ForbiddenFunctions"/>
    <rule ref="Generic.PHP.NoSilencedErrors"/>
    <rule ref="Generic.WhiteSpace.ScopeIndent"/>
    <rule ref="Generic.Formatting.SpaceAfterCast"/>

    <rule ref="Squiz.Classes.ValidClassName">
        <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
    </rule>
</ruleset>

but a simple config like:

<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <rule ref="Generic.WhiteSpace.ScopeIndent"/>
</ruleset>

produces an identical result.

To reproduce Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
    7 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
    8 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
    9 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
    10 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found 0
    |       |     (Generic.WhiteSpace.ScopeIndent.Incorrect)

Expected behavior No errors.

Versions:

Additional context I am actually using the most recent version:

vendor/bin/phpcs --version
PHP_CodeSniffer version 3.6.2 (stable) by Squiz (http://www.squiz.net)
jrfnl commented 2 years ago

Despite https://github.com/squizlabs/PHP_CodeSniffer/pull/3478, there's still Generic.WhiteSpace.ScopeIndent errors when using enums.

PHPCS 3.6.2 was released Dec 2021. Syntax support for PHP 8.1 will be in version 3.7.0, which hasn't been released yet.

Please show some patience, we're all overworked and at the end of our energy after the ridiculous amount of changes for which support needed to be added over the past few years. PHP 7.4, 8.0 and 8.1 have introduced more syntax changes and more impactful deprecations than all the PHP versions from PHP 5.0 - 7.3 combined.

gsherwood commented 2 years ago

I can confirm the issue exists in 3.6.2 but not in master, so this will be fixed in the 3.7.0 release.

The release milestone is listed on all issues and the milestone status lets you know if it's released and what's left to do before release. Here is a direct link for 3.7.0: https://github.com/squizlabs/PHP_CodeSniffer/milestone/28