Stillat / blade-parser-typescript

A Laravel Blade parser, compiler, and static analyzer written in TypeScript.
https://stillat.com
MIT License
82 stars 2 forks source link

Indentation increased repeatedly on each formatter run #95

Closed bakerkretzmar closed 6 months ago

bakerkretzmar commented 6 months ago

Hi! Love this project, thanks so much. If this is the wrong place to submit this issue let me know.

I noticed a very specific and weird issue with the prettier plugin—I have some markup that gets formatted and then indented further and further on each subsequent format. I've simplified the markup a lot here because it still reproduces with this example, but I can share the original too if that's helpful.

Source:

<x-component :prop="array_filter(array_merge([
    [], []
]))" />

Formatted:

<x-component
    :prop="array_filter(array_merge([
        [], []
    ]))"
/>

Everything inside that inner array_merge() gets indented again every time I save, so after a few other changes to the file it looks like this:

<x-component
    :prop="array_filter(array_merge([
                                    [], []
    ]))"
/>

It seems to be related to the fact that the PHP expression starts on the same line as the attribute itself, moving it onto its own lines seems to fix this (although the PHP expression itself isn't formatted and there are still some weird indentation edge cases). So this is my workaround:

<x-component
    :prop="
        array_filter(array_merge([
            [], []
        ]))
    "
/>

I'm totally fine with that, just thought it might be helpful to report anyway. If the easiest solution is just to force long expressions like that onto their own lines like in my workaround, that would be great imo.

JohnathonKoster commented 6 months ago

Nope this is the right spot! I'll make time to look into this later this week as what you had originally shouldn't continuously indent 🙂

JohnathonKoster commented 6 months ago

Resolved and fix available with release 2.1.7