noDuplicateClasses (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.4.0 - Diagnostic Category:
assist/source/noDuplicateClasses - Sources:
- Inspired from
better-tailwindcss/no-duplicate-classes
- Inspired from
How to enable in your editor
Section titled “How to enable in your editor”{ "editor.codeActionsOnSave": { "source.action.noDuplicateClasses.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.action.noDuplicateClasses.biome": true, "source.fixAll.biome": true }}
Use the source action code
source.action.noDuplicateClasses.biome How to configure
Section titled “How to configure”{ "assist": { "actions": { "source": { "noDuplicateClasses": "on" } } }}Description
Section titled “Description”Remove repeated CSS class names.
The action checks JSX class and className attributes by default. It can also check
additional attributes, function calls, and tagged templates configured by name. A tagged
template is a template literal with a function name immediately before its opening backtick.
Duplicate class names are redundant and often indicate a copy-and-paste mistake or merge
conflict.
Examples
Section titled “Examples”<div class="flex flex" />;code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 │ <div·class="flex·flex"·/>;
│ -----
<div class="p-4 text-red-500 p-4 bg-white" />;code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 │ <div·class="p-4·text-red-500·p-4·bg-white"·/>;
│ ----
Options
Section titled “Options”attributes
Section titled “attributes”Adds JSX attributes to check alongside class and className. Defaults to an empty list.
{ "assist": { "actions": { "source": { "noDuplicateClasses": { "level": "on", "options": { "attributes": [ "tw" ] } } } } }}<div tw="flex flex" />code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 │ <div·tw="flex·flex"·/>
│ -----
functions
Section titled “functions”Lists utility functions or tagged templates whose strings contain CSS classes. Defaults to an empty list.
{ "assist": { "actions": { "source": { "noDuplicateClasses": { "level": "on", "options": { "functions": [ "clsx" ] } } } } }}const className = clsx("p-4 p-4");code-block.js ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Source action diff:
1 │ const·className·=·clsx("p-4·p-4");
│ ----
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.