Disallow duplicate selectors within a stylesheet.
在一个样式表中禁止出现重复的选择器。
.foo {} .bar {} .foo {}
/** ↑ ↑
* These duplicates */
This rule checks for two types of duplication:
该规则检查以下两种类型的重复情况:
a, b, a {}
.a, b, a {}
.a, b {} a, b {}
. Duplicates are found even if the selectors come in different orders or have different spacing, e.g. a d, b > c {} b>c, a d {}
.a, b {} a, b {}
。即使选择器以不同的顺序出现,或有不同的空格,也会被认为是重复的,如 a d, b > c {} b>c, a d {}
。The same selector is allowed to repeat in the following circumstances:
以下情况,允许出现重复的选择器:
a {} a, b {}
.a {} a, b {}
.This rule resolves nested selectors. So a b {} a { & b {} }
counts as a warning, because the resolved selectors end up with a duplicate.
该规则适用于嵌套的选择器。因此 a b {} a { & b {} }
会引起警告,因为出现了重复。
true
The following patterns are considered warnings:
以下模式被认为是个警告:
.foo,
.bar,
.foo {}
.foo {}
.bar {}
.foo {}
.foo .bar {}
.bar {}
.foo .bar {}
@media (min-width: 10px) {
.foo {}
.foo {}
}
.foo, .bar {}
.bar, .foo {}
a .foo, b + .bar {}
b+.bar,
a
.foo {}
a b {}
a {
& b {}
}
The following patterns are not considered warnings:
以下模式正常:
.foo {}
@media (min-width: 10px) {
.foo {}
}
.foo {
.foo {}
}
.foo {}
.bar {}
.foo .bar {}
.bar .foo {}
a b {}
a {
& b,
& c {}
}