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

The plugin does not order classes that are specified in a variable outside the className prop #133

Closed
piedrahitapablo opened this issue Mar 18, 2023 · 8 comments · Fixed by #155

Comments

@piedrahitapablo
Copy link

piedrahitapablo commented Mar 18, 2023

What version of prettier-plugin-tailwindcss are you using?

v0.2.5

What version of Tailwind CSS are you using?

v3.2.7

What version of Node.js are you using?

v18.14.2

What package manager are you using?

Yarn

What operating system are you using?

macOS

Reproduction URL

https://github.com/piedrahitapablo/prettier-tailwind-bug

Steps:

git clone git@github.com:piedrahitapablo/prettier-tailwind-bug.git
yarn install
yarn format

that should show you the git diff for the classes that are reordered

Describe your issue

The issue is that this plugin does not order classes that are specified in a variable outside the className prop. If you go to the minimal reproduction repo, you can see that I defined two variables (classes and classes2) that are later used inside the className prop, one inside a template string and the other one as the full value of className but the plugin does not reorder them. In line 24 I used the classnames package inside the className prop and the plugin picks the classes and reorders them, so it's not an issue with that package.

The behavior I would expect is that the plugin reorders those values. I know that can be tricky in some situations and using classnames inside the className prop should cover most cases.

Finally, if the plugin is working as intended, I think adding some clarification on the docs would be great, just saying that the plugin only reorders the classes defined inside the prop.

Happy to help if I can make a PR, just need some pointers on where to start.

Thanks!

@nanxiaobei
Copy link

facing the same demand

@gutisalex
Copy link

same issue when using class variance authority...

@NorrisWu0
Copy link

Would be great to see support for this. ❤️

@GreenTea124
Copy link

GreenTea124 commented Apr 10, 2023

This extension allows custom matching patterns https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss via tailwindCSS.experimental.classRegex. Prettier plugin could support something simmilar. Though it probably wouldn't be very performant.

@MosheRivkin
Copy link

MosheRivkin commented Apr 14, 2023

Check out the prettier-plugin-nativewind, it's allow you to customize
props functions and Tagged Templates.

@rodrigoehlers
Copy link

I agree that this is annoying, however I understand this is a difficult problem to solve. I would suggest having sorting of strings of variables whose names end in classname(s) (case-insensitive).

I can't prove it yet but I don't think this would impact runtime performance by too much. Would this be an option you would be open to add @reinink to the project? I'm happy to implement this.

@thecrypticace
Copy link
Contributor

Hey, we've just merged #155 which provides a way for you to specify additional attributes, functions, and tagged template literals that should be sorted by the plugin. It's available via our insiders build and will be released in the next version of the plugin. We would like to get some feedback on this feature before we release it, so please give it a try and let us know what you think!

To test the new features you can install the insiders build like so:

npm install prettier-plugin-tailwindcss@insiders

@pawelblaszczyk5
Copy link

pawelblaszczyk5 commented May 10, 2023

Hi, I've just wanted to let you know that I've added the insider version to my codebase today and everything works like a breeze! I've managed to configure it to sort every Tailwind occurrence inside of my code. Awesome job and thank you a lot for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants