selector-max-id
Limit the number of ID selectors in a selector.
#foo {}/** ↑ * This type of selector */Use this rule to enforce a convention. For example, limit selectors to 0 IDs, as one ID outweighs any number of classes and makes overriding hard.
Each selector in a selector list is evaluated separately.
This rule supports 2 message arguments: the selector and the configured maximum.
Options
Section titled “Options”number
Section titled “number”Specify a maximum universal selectors allowed.
Given:
{ "selector-max-id": 2}The following pattern is considered a problem:
#foo #bar #baz {}The following patterns are not considered problems:
#foo {}#foo #bar {}.foo #foo {}#foo.foo #bar {}Optional secondary options
Section titled “Optional secondary options”ignoreContextFunctionalPseudoClasses
Section titled “ignoreContextFunctionalPseudoClasses”{ "ignoreContextFunctionalPseudoClasses": [ "array", "of", "pseudo-classes", "/regex/" ]}Ignore selectors inside of the specified functional pseudo-classes.
Given:
{ "selector-max-id": [ 0, { "ignoreContextFunctionalPseudoClasses": [":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) {}