Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Prettier Plugin] Make it possible to sort class names in arbitrary strings #10458

nikwen started this conversation in Ideas
Discussion options

Sometimes it is necessary to have class names in arbitrary strings. It would be great to be able to sort them using the Tailwind CSS Prettier plugin.

Examples:

var className1 = 'sm:p-1 p-0';
let className2 = "sm:p-1 p-0";
const className3 = `sm:p-1 p-0`;
let obj1 = {
 className: "sm:p-1 p-0",
};
let obj2 = {
 ["className"]: Math.random() >= 0.5 ? "sm:p-1 p-0" : "sm:p-2 p-1",
};

This was also requested in tailwindlabs/prettier-plugin-tailwindcss#97.

Implementation ideas

Comments

By @jamescmartinez:

// prettier-plugin-tailwindcss
const base = "mb-4 text-white"

Via the Tailwind CSS Intellisense plugin

There was also a discussion about implementing sorting functionality in the Tailwind CSS Intellisense plugin. I'd advocate against that because:

  • A lot of devs use Jetbrains IDEs instead of VS Code (myself included).
  • It cannot be automated using tools such as husky and lint-staged.
You must be logged in to vote

Replies: 3 comments

Comment options

Agreed about the Intellisense plugin part. Although most if not all members in my team, me included, use VSCode, our workflow should not be made dependent on any specific editors.

You must be logged in to vote
0 replies
Comment options

Yes, I absolutely support this proposal. Sometimes we have some duplicated components and we only wanna take the className out as a variable. But then everytime you edit that variable, you can't be sure the order of those classes is right.

You must be logged in to vote
0 replies
Comment options

I also think this would be useful

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /