Skip to main content

selector-max-class

限制选择器中的类数量。

¥Limit the number of classes in a selector.

div .foo.bar[data-val] > a.baz {}
/* ↑ ↑ ↑
↑ ↑ ↑
1 2 3 -- this selector contains three classes */

此规则在计算选择器中的类数量之前解析嵌套选择器。选择器列表 中的每个选择器都是单独评估的。

¥This rule resolves nested selectors before counting the number of classes in a selector. Each selector in a selector list is evaluated separately.

:not() 伪类也被单独评估。该规则将参数视为独立选择器,并且结果不计入整个选择器的总数。

¥The :not() pseudo-class is also evaluated separately. The rule processes the argument as if it were an independent selector, and the result does not count toward the total for the entire selector.

message 次要选项 可以接受该规则的参数。

¥The message secondary option can accept the arguments of this rule.

选项

¥Options

int:允许的最大类数。

¥int: Maximum classes allowed.

例如,对于 2

¥For example, with 2:

以下模式被视为问题:

¥The following patterns are considered problems:

.foo.bar.baz {}
.foo .bar {
& > .baz {}
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

div {}
.foo .bar {}
.foo.bar,
.lorem.ipsum {} /* each selector in a selector list is evaluated separately */
.foo .bar :not(.lorem.ipsum) {} /* `.lorem.ipsum` is inside `:not()`, so it is evaluated separately */