prettier-plugin-tailwindcss icon indicating copy to clipboard operation
prettier-plugin-tailwindcss copied to clipboard

Classes with custom variable names are not sorted

Open sboerrigter opened this issue 9 months ago • 3 comments

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

0.6.11

What version of Tailwind CSS are you using?

4.1.3

What version of Node.js are you using?

v23.6.1

What package manager are you using?

npm

What operating system are you using?

macOS

Reproduction URL

https://play.tailwindcss.com/DPP55XQUZZ

Describe your issue

Tailwind with custom variable names are not sorted correctly. For example, if the following color variable is defined:

@theme {
  --color-primary-600: var(--color-blue-600);
}

Classes containing -primary-600 are moved to the front of the list. So this:

m-10 text-4xl font-extrabold text-gray-800 hover:text-primary-600

Becomes this:

hover:text-primary-600 m-10 text-4xl font-extrabold text-gray-800

See the example above. I am not sure why the "Tidy" button isn't working there, but if I format this locally, this issue occurs.

sboerrigter avatar Apr 09 '25 07:04 sboerrigter

Hello @sboerrigter, I had the same issue. Turns out that with Tailwind CSS v4, you need to add this option to your Prettier config so that Prettier knows where to find your Tailwind configuration stylesheet:

// .prettierrc
{
  "tailwindStylesheet": "./resources/css/app.css"
}

You can find more about this in the documentation.

Hope this helps! 😊

spicrd avatar Apr 21 '25 00:04 spicrd

I have the same issue with a pnpm monorepo.

vafanassieff avatar Apr 21 '25 16:04 vafanassieff

Hello @sboerrigter, I had the same issue. Turns out that with Tailwind CSS v4, you need to add this option to your Prettier config so that Prettier knows where to find your Tailwind configuration stylesheet:

// .prettierrc
{
  "tailwindStylesheet": "./resources/css/app.css"
}

You can find more about this in the documentation.

Hope this helps! 😊

It works! Thank you. 😊

rsstacks avatar Apr 23 '25 14:04 rsstacks

@sboerrigter Without a reproduction repo I can't really triage this. But it's quite likely the above. You need to specify your stylesheet in your Prettier config file.

If it doesn't work after doing that please provide a repro and @-mention me again on this issue and I'll take another look.

thecrypticace avatar Jul 01 '25 17:07 thecrypticace