useSortedClasses (not released)
Enforce the sorting of CSS utility classes.
It is analogous to
ExamplesSection titled Examples
InvalidSection titled Invalid
nursery/useSortedClasses.js:1:12 lint/nursery/useSortedClasses FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ These CSS classes should be sorted.
> 1 │ <div class="px-2 foo p-4 bar" />;
ℹ 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 │
OptionsSection titled Options
Code-relatedSection titled Code-related
attributesSection titled attributes
Classes in the
className JSX attributes are always sorted. Use this option to add more attributes that should be sorted.
functionsSection titled functions
Tagged template literals are also supported, for example:
Sort-relatedSection titled Sort-related
The main key difference is that Tailwind CSS and its Prettier plugin read and execute the
Values are not knownSection titled Values are not known
The rule has no knowledge of values such as colors, font sizes, or spacing values, which are normally defined in a configuration file like
tailwind.config.js. Instead, the rule matches utilities that support values in a simpler way: if they start with a known utility prefix, such as
text-, they’re considered valid.
This has two implications:
- False positives: classes can be wrongly recognized as utilities even though their values are incorrect. For example, if there’s a
px-utility defined in the configuration, it will match all of the following classes:
- No distinction between different utilities that share the same prefix: for example,
text-lgare both interpreted as the same type of utility by this rule, even though the former refers to a color and the latter to a font size. This results in all utilities that share the same prefix being sorted together, regardless of their actual values.
Custom additions must be specifiedSection titled Custom additions must be specified
The built-in Tailwind CSS preset (enabled by default) contains the set of utilities and variants that are available with the default configuration. More utilities and variants can be added through Tailwind CSS plugins. In Biome, these need to be manually specified in the Biome configuration file in order to “extend” the preset.
Presets can’t be modifiedSection titled Presets can’t be modified
In Tailwind CSS, core plugins (which provide the default utilities and variants) can be disabled. In Biome, however, there is no way to disable parts of a preset: it’s all or nothing. A work-around is to, instead of using a preset, manually specify all utilities and variants in the Biome configuration file.
Whitespace is collapsedSection 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.