useTailwindSortedClasses (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v1.6.0 - Diagnostic Category:
lint/nursery/useTailwindSortedClasses - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Inspired from
better-tailwindcss/enforce-consistent-class-order - Inspired from
tailwindcss/classnames-order
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useTailwindSortedClasses": "error" } } }}Description
Section titled “Description”Enforce the sorting of Tailwind CSS classes.
Classes are sorted in the same order as the official Tailwind CSS Prettier plugin, which is the order in which Tailwind CSS writes their CSS. Classes that Tailwind CSS doesn’t know, such as your own CSS classes, come first and keep their original order.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<div class="px-2 foo p-4 bar" />;code-block.jsx:1:12 lint/nursery/useTailwindSortedClasses FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ These CSS classes should be sorted.
> 1 │ <div class="px-2 foo p-4 bar" />;
│ ^^^^^^^^^^^^^^^^^^
2 │
ℹ A consistent class order makes class lists easier to read and keeps changes to them small.
ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/1274 for more information or to report possible bugs.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Sort the classes.
1 │ - <div·class="px-2·foo·p-4·bar"·/>;
1 │ + <div·class="foo·bar·p-4·px-2"·/>;
2 2 │
<div class="hover:focus:m-2 foo hover:px-2 p-4" />code-block.jsx:1:12 lint/nursery/useTailwindSortedClasses FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ These CSS classes should be sorted.
> 1 │ <div class="hover:focus:m-2 foo hover:px-2 p-4" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ A consistent class order makes class lists easier to read and keeps changes to them small.
ℹ This rule is still being actively worked on, so it may be missing features or have rough edges. Visit https://github.com/biomejs/biome/issues/1274 for more information or to report possible bugs.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Sort the classes.
1 │ - <div·class="hover:focus:m-2·foo·hover:px-2·p-4"·/>
1 │ + <div·class="foo·p-4·hover:px-2·hover:focus:m-2"·/>
2 2 │
<div class="foo bar p-4 px-2" />;Recognized class strings
Section titled “Recognized class strings”This rule checks the attributes and functions recognized by the top-level
tailwind configuration.
Differences with Prettier
Section titled “Differences with Prettier”Whitespace is collapsed
Section titled “Whitespace is collapsed”The Tailwind CSS Prettier plugin preserves all original whitespace. This rule, however, collapses all whitespace (including newlines) into single spaces.
This is a deliberate decision. We’re unsure about this behavior, and would appreciate feedback on it. If this is a problem for you, please share a detailed explanation of your use case in the GitHub issue.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.