prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.75k stars 130 forks source link

Syntax error when attributes are defined to enum cases #2293

Open kapersoft opened 10 months ago

kapersoft commented 10 months ago

@prettier/plugin-php v0.22.1 Playground link

Input:

<?php

namespace App\Enums;

use App\Support\Attributes\Description;

enum SalutationEnum: string
{
    #[Description('Mr.')]
    case MR = 'mr';

    #[Description('Mrs.')]
    case MRS = 'mrs';

    #[Description('Miss')]
    case MISS = 'miss';
}

Output:

Parse Error : syntax error, unexpected 'case' (T_CASE) on line 10

   8 | {
   9 |     #[Description('Mr.')]
> 10 |     case MR = 'mr';
     |    ^
  11 |
  12 |     #[Description('Mrs.')]
  13 |     case MRS = 'mrs';

I got the idea of using attributes to describe enum cases from this blogpost. The php code runs fine without any issues, but Prettier thinks it's a syntax error.