prettier / plugin-php

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

prettier-ignore breaking the ignored line #1222

Open c17r opened 4 years ago

c17r commented 4 years ago

@prettier/plugin-php v0.11.2 Playground link

Input:

<?php

namespace App;

class Carousel extends Model
{
    protected $table = 'carousels';

    // prettier-ignore
    protected $fillable = [
        'status_id',
        'type',
        'image_path',
        'alt_text',
        'url',
        'begin_datetime',
        'end_datetime',
    ];

    protected $casts = [
        'begin_datetime' => 'datetime',
        'end_datetime' => 'datetime',
    ];
}

Output:

<?php

namespace App;

class Carousel extends Model
{
    protected $table = 'carousels';

    // prettier-ignore
    $fillable = [
        'status_id',
        'type',
        'image_path',
        'alt_text',
        'url',
        'begin_datetime',
        'end_datetime',
    ]

    protected $casts = [
        'begin_datetime' => 'datetime',
        'end_datetime' => 'datetime'
    ];
}
czosel commented 4 years ago

This is due to a bug in the parser: https://github.com/glayzzle/php-parser/issues/511

erropix commented 3 years ago

@c17r @czosel I found a workaround to this issue, just put the // prettier-ignore inside the array, and it will be formatted correctly

<?php

namespace App;

class Carousel extends Model
{
    protected $fillable = [
        // prettier-ignore
        'status_id',
        'type',
        'image_path',
        'alt_text',
        'url',
        'begin_datetime',
        'end_datetime',
    ];
}