vscode-blade-formatter icon indicating copy to clipboard operation
vscode-blade-formatter copied to clipboard

Conditioning classes with directives is lost with Tailwind sorting

Open Random72IsTaken opened this issue 3 years ago • 1 comments

Code

<!-- Case 1 | At The Beginning -->
<div class="@auth bg-neutral-100 @endauth relative h-10 w-10"></div>
<div class="@if (true) bg-neutral-100 @endif relative h-10 w-10"></div>

<!-- Case 2 | In The Middle -->
<div class="relative @auth bg-neutral-100 @endauth h-10 w-10"></div>
<div class="relative @if (true) bg-neutral-100 @endif h-10 w-10"></div>

<!-- Case 3 | At The End -->
<div class="relative h-10 w-10 @auth bg-neutral-100 @endauth"></div>
<div class="relative h-10 w-10 @if (true) bg-neutral-100 @endif"></div>

Formatted

<!-- Case 1 | At The Beginning -->
<div class="@auth @endauth relative h-10 w-10 bg-neutral-100"></div>
<div class="@if (true) bg-neutral-100 @endif relative h-10 w-10"></div>

<!-- Case 2 | In The Middle -->
<div class="@auth @endauth relative h-10 w-10 bg-neutral-100"></div>
<div class="@if (true) bg-neutral-100 @endif relative h-10 w-10"></div>

<!-- Case 3 | At The End -->
<div class="@auth @endauth relative h-10 w-10 bg-neutral-100"></div>
<div class="@if (true) bg-neutral-100 @endif relative h-10 w-10"></div>

Expectation

To be formatted without losing the inner classes. While I don't think order matters for now; either first or last; keeping the classes conditioned definitely is.

Observation

Even though it shouldn't be like that, but I noticed that if you wrap the inner classes with apostrophes ', it preserves what's inside as recognized string, I presume... -Hope this is helpful. 🥲

Random72IsTaken avatar Aug 10 '22 15:08 Random72IsTaken

Before @class() directive came out, we used to use this conditioning a lot for classes. That's why I thought it's worth reporting.

<div @class([
        'relative h-10 w-10', // Default classes
        'bg-neutral-100' => true,
        'bg-black' => auth()->check(),
     ])>
    <p>Hey there!</p>
</div>

Random72IsTaken avatar Aug 10 '22 17:08 Random72IsTaken

Thanks a bunch! :)

Random72IsTaken avatar Aug 28 '22 14:08 Random72IsTaken

Fixed at https://github.com/shufo/vscode-blade-formatter/releases/tag/v0.17.3

shufo avatar Aug 28 '22 22:08 shufo