Skip to content

noDuplicateClasses (JavaScript)

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.action.noDuplicateClasses.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
biome.json
{
"assist": {
"actions": {
"source": {
"noDuplicateClasses": "on"
}
}
}
}

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.

<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"·/>;
│ ----

Adds JSX attributes to check alongside class and className. Defaults to an empty list.

biome.json
{
"assist": {
"actions": {
"source": {
"noDuplicateClasses": {
"level": "on",
"options": {
"attributes": [
"tw"
]
}
}
}
}
}
}
<div tw="flex flex" />
code-block.jsx ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ Source action diff:

1 │ <div·tw="flex·flex"·/>
│ -----

Lists utility functions or tagged templates whose strings contain CSS classes. Defaults to an empty list.

biome.json
{
"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");
│ ----