Skip to main content

selector-max-id

限制选择器中 ID 选择器的数量。

¥Limit the number of ID selectors in a selector.

    #foo {}
/** ↑

* This type of selector */

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

¥This rule resolves nested selectors before counting the number of ID selectors. 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 universal selectors allowed.

例如,对于 2

¥For example, with 2:

以下模式被视为问题:

¥The following patterns are considered problems:

#foo #bar #baz {}
#foo #bar {
& #baz {}
}
#foo #bar {
& > #bar {}
}

以下模式不被视为问题:

¥The following patterns are not considered problems:

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

可选的辅助选项

¥Optional secondary options

checkContextFunctionalPseudoClasses: ["/regex/", /regex/, "non-regex"]

检查提供 评估环境 的指定自定义 函数式伪类 中的选择器。

¥Check selectors inside of the specified custom functional pseudo-classes that provide evaluation contexts.

此选项的优先级高于 ignoreContextFunctionalPseudoClasses

¥This option has a higher precedence than ignoreContextFunctionalPseudoClasses.

鉴于:

¥Given:

[":--foo"]

以下模式被认为是一个问题:

¥The following pattern is considered a problem:

:--foo(#foo #bar #baz) {}

以下模式不被视为问题:

¥The following pattern is not considered a problem:

:--foo() {}

ignoreContextFunctionalPseudoClasses: ["/regex/", /regex/, "non-regex"]

忽略指定 函数式伪类 内提供 评估环境 的选择器。

¥Ignore selectors inside of the specified functional pseudo-classes that provide evaluation contexts.

鉴于:

¥Given:

[":not", "/^:(h|H)as$/"]

以下模式被视为问题:

¥The following patterns are considered problems:

a:is(#foo) {}

以下模式不被视为问题:

¥The following patterns are not considered problems:

a:not(#foo) {}
a:has(#foo) {}