eslint-plugin-tailwindcss: [BUG] Prettier class order don't match with eslint-plugin-tailwindcss

Describe the bug With the prettier and eslint plugin installed in some cases the class order don’t match.

To Reproduce Steps to reproduce the behavior: In a div element add the classes top-0 left-0 prettier will not change the class orders but there will be an eslint error applying eslint fix will satisfy both eslint and prettier plugin the class names should now be left-0 top-0

Expected behavior when I format with prettier, this error should go away

Screenshots If applicable, add screenshots to help explain your problem. With prettier formating: image

With eslint fix applied (prettier is ok as well with this one): image

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 8
  • Comments: 18 (3 by maintainers)

Most upvoted comments

There is no need for a Prettier plugin if this ESLint plugin is installed. But if you still want to use both, you can disable a ESLint rule that sorts class names:

// .eslintrc
module.exports = {
  extends: [
    "...",
    "plugin:tailwindcss/recommended",
  ],
  rules: {
    "...": "...",
    "tailwindcss/classnames-order": "off"
  }
};

Note that what prettier-plugin-tailwindcss does is outside the scope of Prettier:

Prettier only prints code. It does not transform it. This is to limit the scope of Prettier. Let’s focus on the printing and do it really well!

Here are a few examples of things that are out of scope for Prettier:

  • Turning single- or double-quoted strings into template literals or vice versa.
  • Using + to break long string literals into parts that fit the print width.
  • Adding/removing {} and return where they are optional.
  • Turning ?: into if-else statements.
  • Sorting/moving imports, object keys, class members, JSX keys, CSS properties or anything else. Apart from being a transform rather than just printing (as mentioned above), sorting is potentially unsafe because of side effects (for imports, as an example) and makes it difficult to verify the most important correctness goal.

Here it conflicts both ways, brandPrimary is a custom color

prettier outline-brandPrimary p-2

eslint-config-tailwindcss p-2 outline-brandPrimary

I’ll look if i can find an example with no custom themes

+1 conflicting mx-2 flex vs flex mx-2