vscode-blade-formatter
vscode-blade-formatter copied to clipboard
Conditioning classes with directives is lost with Tailwind sorting
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. 🥲
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>
Thanks a bunch! :)
Fixed at https://github.com/shufo/vscode-blade-formatter/releases/tag/v0.17.3