noDuplicateSelectors
此内容尚不支持你的语言。
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.
This rule checks for duplicate selectors across a stylesheet. A duplicate occurs when two rules have the same fully-resolved selector list (after sorting for order-independence), within the same at-rule context.
Selectors are normalized before comparison so that equivalent selectors written differently are still caught:
- Whitespace differences are ignored.
- HTML type selectors are compared case-insensitively (
DIV==div). - Compound selector parts are order-normalized, so
.a.band.b.aare considered equal. - Selector list order is ignored:
.a, .band.b, .aare equal.
CSS nesting is fully resolved before comparison:
a { & b {} } produces the resolved selector a b, which is compared
against all other resolved selectors in the same context.
Selectors are only compared within the same at-rule context. A selector
inside @media is not considered a duplicate of the same 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.