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

ScopeIndent reports wrong indentation in enums #3572

Closed
dingo-d opened this issue Mar 31, 2022 · 5 comments
Closed

ScopeIndent reports wrong indentation in enums #3572

dingo-d opened this issue Mar 31, 2022 · 5 comments

Comments

@dingo-d
Copy link

dingo-d commented Mar 31, 2022

Describe the bug
The file with an enum reports wrong indentation level (0 instead of 4)

Code sample

<?php

namespace App\Enums;

enum ProjectStatus: string
{
	case ACTIVE = 'Active';
	case ON_HOLD = 'On hold';
	case FROM_TIME_TO_TIME = 'From time to time';
	case UNKNOWN = 'Unknown';
	case DONE = 'Done';
	case UPCOMING = 'Upcoming';
	case DEPRECATED = 'Deprecated';
	case OFFBOARDING = 'Offboarding';
	case MAINTENANCE = 'Maintenance';
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="Custom ruleset">

	<file>.</file>
	
	<!-- Additional arguments. -->
	<arg value="sp"/>
	<arg name="cache"/>
	<arg name="basepath" value="."/>
	<arg name="parallel" value="8"/>
	<arg name="extensions" value="php"/>

	<!-- Apply PSR12 coding standards across the repo. -->
	<rule ref="PSR12" />

	<!-- Tabs should represent 4 spaces. -->
	<arg name="tab-width" value="4"/>

	<!-- Indent using tabs. -->
	<rule ref="Generic.WhiteSpace">
		<exclude name="Generic.WhiteSpace.DisallowTabIndent.TabsUsed" />
		<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
		<rule ref="Generic.WhiteSpace.ScopeIndent">
			<properties>
				<property name="tabIndent" value="true" />
			</properties>
		</rule>
	</rule>
</ruleset>

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
FILE: phpcs-test.php
----------------------------------------------------------------------------------------------------------------------------
FOUND 10 ERRORS AFFECTING 10 LINES
----------------------------------------------------------------------------------------------------------------------------
  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 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 11 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 12 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 13 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 14 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 15 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4 (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 16 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found 0
    |       |     (Generic.WhiteSpace.ScopeIndent.Incorrect)
----------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------

The 'fixed' file looks like this:

<?php

namespace App\Enums;

enum ProjectStatus: string
{
case ACTIVE = 'Active';
case ON_HOLD = 'On hold';
case FROM_TIME_TO_TIME = 'From time to time';
case UNKNOWN = 'Unknown';
case DONE = 'Done';
case UPCOMING = 'Upcoming';
case DEPRECATED = 'Deprecated';
case OFFBOARDING = 'Offboarding';
case MAINTENANCE = 'Maintenance';
	}

Expected behavior
There shouldn't be any errors reported.

Versions (please complete the following information):

  • OS: Windows 11, phpcs script runs inside WSL2 with Ubuntu 20.04
  • PHP: 8.1
  • PHPCS: 3.6.0
  • Standard: Generic, PSR12
@jrfnl
Copy link
Contributor

jrfnl commented Mar 31, 2022

PHP 8.1 support is not complete yet and most definitely not included in PHPCS 3.6.0, which is a release from before the PHP 8.1 alpha was available.

See #3479 for an overview of the current status.

Enum support is expected in PHPCS 3.7.0.
See: #3478, #3482, #3483

@dingo-d
Copy link
Author

dingo-d commented Mar 31, 2022

Wasn't aware of that, I've added this as an exclusion for now, not a huge problem 🙂

@gsherwood
Copy link
Member

Closing as have confirmed indent checks are fixed in upcoming release. This is being tracked on the issues listed above.

@lewiscowleschipuk
Copy link

Should this still be happening in 3.6.2?

@jrfnl
Copy link
Contributor

jrfnl commented Apr 14, 2022

@lewiscowleschipuk Yes. Enum support has been added and will be included in the 3.7.0 release.

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

No branches or pull requests

4 participants