Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support Tailwind automatic class sorting #14

Closed
elliotwaite opened this issue Mar 28, 2023 · 4 comments
Closed

Feature request: support Tailwind automatic class sorting #14

elliotwaite opened this issue Mar 28, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@elliotwaite
Copy link

Tailwind supports automatic class sorting with Prettier. It would be nice if this formatter could somehow incorporate that functionality. Perhaps it could be an optional feature, that if enabled, would check if a class attribute was a string literal, and if so, it would sort the class names in that string similarly to how prettier-plugin-tailwindcss does it.

@bram209 bram209 added the enhancement New feature or request label Mar 28, 2023
@elliotwaite
Copy link
Author

Actually, adding this feature to leptosfmt may not be needed. I just found a tool called rustywind that already accomplishes this, and I set up an automatic file watcher in my IDE that runs rustywind on the current file (if it's a Rust file) whenever I save it.

It also probably makes sense to leave the responsibility of Tailwind class sorting to an external tool, since Tailwind class sorting can also apply to code outside the view! macro. For example, rustywind will automatically sort string literals of classes that are assigned to variables named class. For example, this:

let class = "text-white px-4 sm:px-8 py-2 sm:py-3 bg-sky-700 hover:bg-sky-800";

...will become this:

let class = "py-2 px-4 text-white sm:py-3 sm:px-8 bg-sky-700 hover:bg-sky-800";

If you agree that this feature should be handled by an external tool like rustywind, feel free to close this issue. But it might be a good idea to add a mention of rustywind to the README, in case there are other Tailwind users who are also wondering about the same thing.

@bram209
Copy link
Owner

bram209 commented Mar 28, 2023

It also probably makes sense to leave the responsibility of Tailwind class sorting to an external tool

This was my thought as well, unfortunately there is no such thing as a plugin system for rustfmt (like prettier has).

On another note, I think the tailwind language server is regex based, so you could configure that to work with the leptos syntax as well (for auto-completions etc)

@elliotwaite
Copy link
Author

On another note, I think the tailwind language server is regex based, so you could configure that to work with the leptos syntax as well (for auto-completions etc)

Good to know. Getting auto-completions to work as well would be nice.

@bram209
Copy link
Owner

bram209 commented Mar 29, 2023

On another note, I think the tailwind language server is regex based, so you could configure that to work with the leptos syntax as well (for auto-completions etc)

Good to know. Getting auto-completions to work as well would be nice.

I looked it up, you have a tailwindCSS.experimental.classRegex setting, someone curated a list of examples here:
https://github.com/paolotiu/tailwind-intellisense-regex-list

I will close this issue then, considering there are other solutions already out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants