Stillat / blade-parser-typescript

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

Styles indented every time formatter is run #45

Closed zepfietje closed 1 year ago

zepfietje commented 1 year ago

This is an issue that occurs when running the formatter on the Filament codebase. I've simplified it to the minimal amount of code that reproduces the issue:

<style>
    :root {
        --foo: red;

        @if (true)
            --bar: blue;
        @endif
    }
</style>

Every time the formatter is run, the styles get indented:

<style>
    :root {
            --foo: red;

            @if (true)
                --bar: blue;
            @endif
        }
</style>

Running it again:

<style>
    :root {
                --foo: red;

                @if (true)
                    --bar: blue;
                @endif
            }
</style>

The original code really doesn't need any formatting at all.

JohnathonKoster commented 1 year ago

Corrected in 1.3.0 🙂

zepfietje commented 1 year ago

Thanks, John. I found the issue still occurs when the code is already indented/wrapped though:

<div>
    <style>
        :root {
            --foo: red;

            @if (true)
                --bar: blue;
            @endif
        }
    </style>
</div>
<div>
    <style>
        :root {
                    --foo: red;

                    @if (true)
                        --bar: blue;
                    @endif
                }
    </style>
</div>
JohnathonKoster commented 1 year ago

Oh that was a tough one; but got it in 1.3.1 while preserving the existing test cases👍

zepfietje commented 1 year ago

Glad you got it working!