Skip to main content

selector-max-universal

限制选择器中通用选择器的数量。

¥Limit the number of universal selectors in a selector.


* {}
/** ↑

* This universal selector */

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

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

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

¥The logical combinations pseudo-class (e.g. :not, :has) 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.

选项

¥Options

number

指定允许的最大通用选择器数量。

¥Specify a maximum universal selectors allowed.

鉴于:

¥Given:

{
"selector-max-universal": 2
}

以下模式被视为问题:

¥The following patterns are considered problems:


* * * {}

* * {
& * {}
}

* * {
& > * {}
}

以下模式不被视为问题:

¥The following patterns are not considered problems:


* {}

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

* > * .foo:not(*) {}

可选的辅助选项

¥Optional secondary options

ignoreAfterCombinators

{ "ignoreAfterCombinators": ["array", "of", "combinators"] }

忽略指定组合器之一之后的通用选择器。

¥Ignore universal selectors that come after one of the specified combinators.

鉴于:

¥Given:

{
"selector-max-universal": [2, { "ignoreAfterCombinators": [">", "+"] }]
}

以下模式不被视为问题:

¥The following pattern is not considered a problem:


* * > * {}