bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
258 stars 27 forks source link

Remove multiple spaces and format multiline for string attributes #103

Closed cedeber closed 7 months ago

cedeber commented 7 months ago

That can be done for all attributes but I think the most useful case could be the class attribute.

First example is:

<div class="too     much    spaces" />

or, especially useful with Tailwind craziness:

<button class="flex justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2  focus-visible:outline-indigo-600">
Click me
</button>

could be

<button
    class="flex justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6
    text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 
    focus-visible:outline-offset-2  focus-visible:outline-indigo-600"
>
bram209 commented 7 months ago

I am not sure that we can blindly do this for arbitrary attribute values? Sometimes the spacing might be intended, I don't we should make that assumption tbh.

As for formatting tailwind classes, have you looked at #14 ? An external tool such as https://github.com/avencera/rustywind can both sort & (assumably) strip any unnecessary whitespace from your tailwind classes.

bram209 commented 7 months ago

closing this, feel free to reopen if above suggestion is not workable for you