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

Blank lines around enum cases #6214

Closed
gharlan opened this issue Jan 2, 2022 · 9 comments · Fixed by #6426
Closed

Blank lines around enum cases #6214

gharlan opened this issue Jan 2, 2022 · 9 comments · Fixed by #6426
Labels

Comments

@gharlan
Copy link
Contributor

gharlan commented Jan 2, 2022

Bug report

  • PHP 8.1
  • PHP-CS-Fixer 3.4.1-DEV
  • Ruleset @PhpCsFixer

Code snippet that reproduces the problem

<?php

enum Foo {
    case Bar;
    case Baz;
    
    public function abc()
    {
    }
}

This is fixes to:

<?php

enum Foo {
    case Bar;

    case Baz;
    public function abc()
    {
    }
}

Applied fixers are no_extra_blank_lines and blank_line_before_statement.

I would expect no changes instead.

@Bilge
Copy link

Bilge commented Jan 21, 2022

In my view, blank_line_before_statement, even with 'statements' => ['case'], should not affect enum cases because cases as they exists within switch statements, and as they were originally intended by this fixer, have very different semantics to enum cases. I think a good way forward would be to add a separate enum_case option for these new cases in PHP 8.1 enumerations. (It may also be desirable to introduce a companion switch_case option and deprecate the case option).

Aside, I wish they hadn't reused case for enum declarations, but we can't change that now.

@Bilge
Copy link

Bilge commented Feb 11, 2022

@SpacePossum what do you think?

@SpacePossum
Copy link
Contributor

I'm working through a bunch of enum cases here #6280 and @gharlan also has a POC around enum work. Will take some time, but we are working through it, thanks for raising the issue, it is in the back of my mind 👍

@ozahorulia
Copy link

Any progress on this one?

@BenMorel
Copy link
Contributor

BenMorel commented Apr 4, 2022

Similar issue here with CS fixer v3.8.0:

enum UserMessageSeverity: int
{
    case INFO = 1;
    case WARNING = 2;
    case ERROR = 3;
    public function compareTo(UserMessageSeverity $other): int
    {
        return $this->value <=> $other->value;
    }
}

CS fixer does not add any space between cases for me, but does annoyingly remove the blank line before the function.

@othyn
Copy link

othyn commented Apr 28, 2022

Any update on this? Or a temporary workaround? 😄

@XGhozt
Copy link

XGhozt commented May 5, 2022

+1

This is driving me nuts. It's removing blank lines around all the cases.

@jzecca
Copy link

jzecca commented May 28, 2022

Any update on this? Or a temporary workaround?

I keep all my enums in a single directory and exclude it from the fixer conf:

// .php-cs-fixer.dist.php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__.'/src')
    ->exclude(['Enums'])  // exclude directories named "Enums"
;

Definitely not ideal, but at least I'm free to add empty lines wherever I want to.

@SpacePossum
Copy link
Contributor

if some of you have time to test and/or review #6426 it will be much appreciated

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