noDuplicateSelectors (CSS)
Language CSS
Summary
Section titled “Summary”- Rule available since:
v2.4.9 - Diagnostic Category:
lint/nursery/noDuplicateSelectors - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-duplicate-selectors
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noDuplicateSelectors": "error" } } }}Description
Section titled “Description”Disallow duplicate selectors.
Two rules are duplicates when their selectors target the same elements within the same surrounding at-rules. The comparison treats equivalent spellings as equal:
- whitespace differences are ignored;
- HTML element names are compared without case (
DIVequalsdiv); - the order of combined parts is ignored (
.a.bequals.b.a); - the order of a selector list is ignored (
.a, .bequals.b, .a).
Nested selectors are expanded before comparison. For example, a { & b {} } is compared as
a b. A selector inside an at-rule such as @media is compared only with selectors inside
the same at-rule, not with a matching selector at the top level.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”.foo {}.foo {}code-block.css:2:1 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Duplicate selector list ".foo".
1 │ .foo {}
> 2 │ .foo {}
│ ^^^^^^^
3 │
ℹ It was first defined here.
> 1 │ .foo {}
│ ^^^^^^^
2 │ .foo {}
3 │
ℹ Remove or merge the duplicate rule to keep the stylesheet clean.
ℹ 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.
.foo, .bar {}.bar, .foo {}code-block.css:2:1 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Duplicate selector list ".bar, .foo".
1 │ .foo, .bar {}
> 2 │ .bar, .foo {}
│ ^^^^^^^^^^^^^
3 │
ℹ It was first defined here.
> 1 │ .foo, .bar {}
│ ^^^^^^^^^^^^^
2 │ .bar, .foo {}
3 │
ℹ Remove or merge the duplicate rule to keep the stylesheet clean.
ℹ 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.
a b {}a { & b {}}code-block.css:3:3 lint/nursery/noDuplicateSelectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Duplicate selector list "a b".
1 │ a b {}
2 │ a {
> 3 │ & b {}
│ ^^^^^^
4 │ }
5 │
ℹ It was first defined here.
> 1 │ a b {}
│ ^^^^^^
2 │ a {
3 │ & b {}
ℹ Remove or merge the duplicate rule to keep the stylesheet clean.
ℹ 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.
.foo {}.bar {}.foo {}@media (min-width: 600px) { .foo {}}.foo { .foo {}}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.