blade-parser-typescript icon indicating copy to clipboard operation
blade-parser-typescript copied to clipboard

Adds unnecessary lines and incorrect format on some edge cases

Open mansoorkhan96 opened this issue 7 months ago • 0 comments

I am loving this plugin so much. Thank you @JohnathonKoster for the amazing work ❤️❤️❤️.

I am hitting some edge cases where it adds unnecessary lines and if you keep formatting, it keeps on adding those lines and tabs repeatedly:

Simple Example:

Before Formatting

<div
    x-bind:style="() => {
        @foreach ($secondaryFeatures as $index => $feature)
            if (activeTab === @js($feature['name'])) {
                return 'transform: translateX(-' + @js($index * 100) + '%)';
            }
        @endforeach
    }"
></div>

After Formatting

<div
    x-bind:style="() => {
        @foreach ($secondaryFeatures as $index => $feature)

            if (activeTab === @js($feature['name'])) {
                return 'transform: translateX(-' + @js($index * 100) + '%)';
            }
        @endforeach

    }"
></div>

Complex Example:

This block of code gets formatted incorrectly, the plugin adds extra/unexpected lines. This could also be a result of incorrect configuration, I am not sure.

Before Formatting

<div
    x-bind:style="() => {
        @php $index = 0; @endphp

        @foreach ($secondaryFeatures as $feature)
            if (activeTab === @js($feature['name'])) {
                return 'transform: translateX(-' + @js($index * 100) + '%)';
            }

            @php $index++; @endphp
        @endforeach
    }"
></div>

After Formatting

<div
    x-bind:style="() => {
        @php
        $index = 0;

@endphp
        @foreach ($secondaryFeatures as $feature)

            if (activeTab === @js($feature['name'])) {
                return 'transform: translateX(-' + @js($index * 100) + '%)';
            }

            @php
$index++;


@endphp
        @endforeach

    }"
></div>

NOTE: These are not made up examples 😁. I have extracted these examples from a codebase and tweaked a little to just demonstrate only the problematic part. Hope it helps.

mansoorkhan96 avatar Jun 05 '25 16:06 mansoorkhan96