plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

prettier-ignore breaking the ignored line

Open c17r opened this issue 5 years ago • 2 comments

@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'
    ];
}

c17r avatar Nov 15 '19 19:11 c17r

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

czosel avatar Mar 21 '20 19:03 czosel

@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',
    ];
}

erropix avatar Sep 21 '21 23:09 erropix