shufo / blade-formatter

An opinionated blade template formatter for Laravel that respects readability
https://www.npmjs.com/package/blade-formatter
MIT License
441 stars 24 forks source link

[Formatting Bug]: @php block formatting should more closely match output of plugin-php #908

Closed claytonrcarter closed 7 months ago

claytonrcarter commented 7 months ago

Version

1.40.1

Template before formatting

@php
    $a =
        'arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrss';

    $arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr = [
        'arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr',
        [
            'background-color: red',
            'font-weight: bold' => $isActive,
            'font-weight: bold' => $isActive,
        ],
    ];

    $categories = App\Models\Category::whereIn('id', $catids)
        ->orderBy('description')
        ->get();

    $zipIsForShipping = !(
        $order->isGroupPart() ||
        $order->isPickup() ||
        $order->isDepot() ||
        $order->isNofaDepot()
    );

    $data = [
        [
            'href' => '#',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
        ],
    ];
@endphp

Template after formatting

@php
    $a = 'arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrss';

    $arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr = ['arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr', ['background-color: red', 'font-weight: bold' => $isActive, 'font-weight: bold' => $isActive]];

    $categories = App\Models\Category::whereIn('id', $catids)->orderBy('description')->get();

    $zipIsForShipping = !($order->isGroupPart() || $order->isPickup() || $order->isDepot() || $order->isNofaDepot());

    $data = [
        [
            'href' => '#',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
        ],
    ];
@endphp

Expected Behaviour

The code in the input template has been formatted w/ @prettier/plugin-php and copied into the blade template, but blade-formatter then crams nearly every statement onto a single line. I would expect it to format the code more or less unchanged to match how the PHP plugin formats things.

@php
    $a =
        'arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrss';

    $arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr = [
        'arstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasrtarstasr',
        [
            'background-color: red',
            'font-weight: bold' => $isActive,
            'font-weight: bold' => $isActive,
        ],
    ];

    $categories = App\Models\Category::whereIn('id', $catids)
        ->orderBy('description')
        ->get();

    $zipIsForShipping = !(
        $order->isGroupPart() ||
        $order->isPickup() ||
        $order->isDepot() ||
        $order->isNofaDepot()
    );

    $data = [
        [
            'href' => '#',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
            'title' => 'Hi!',
        ],
    ];
@endphp

Note that part of this template is copied from https://github.com/shufo/prettier-plugin-blade/issues/266. If I format this template w/ blade-formatter 1.38.6, most of the template after formatting is the same, but the chained method call (3rd statement) is formatted correctly.

Relevant log output

No response