1 | # selector-max-id
|
2 |
|
3 | Limit the number of ID selectors in a selector.
|
4 |
|
5 |
|
6 | ```css
|
7 | #foo {}
|
8 | /** ↑
|
9 | * This type of selector */
|
10 | ```
|
11 |
|
12 | This rule resolves nested selectors before counting the number of ID selectors. Each selector in a [selector list](https://www.w3.org/TR/selectors4/#selector-list) is evaluated separately.
|
13 |
|
14 | 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.
|
15 |
|
16 | ## Options
|
17 |
|
18 | `int`: Maximum universal selectors allowed.
|
19 |
|
20 | For example, with `2`:
|
21 |
|
22 | The following patterns are considered violations:
|
23 |
|
24 |
|
25 | ```css
|
26 | #foo #bar #baz {}
|
27 | ```
|
28 |
|
29 |
|
30 | ```css
|
31 | #foo #bar {
|
32 | & #baz {}
|
33 | }
|
34 | ```
|
35 |
|
36 |
|
37 | ```css
|
38 | #foo #bar {
|
39 | & > #bar {}
|
40 | }
|
41 | ```
|
42 |
|
43 | The following patterns are _not_ considered violations:
|
44 |
|
45 |
|
46 | ```css
|
47 | #foo {}
|
48 | ```
|
49 |
|
50 |
|
51 | ```css
|
52 | #foo #bar {}
|
53 | ```
|
54 |
|
55 |
|
56 | ```css
|
57 | .foo #foo {}
|
58 | ```
|
59 |
|
60 |
|
61 | ```css
|
62 | #foo.foo #bar {}
|
63 | ```
|
64 |
|
65 |
|
66 | ```css
|
67 | /* each selector in a selector list is evaluated separately */
|
68 | #foo,
|
69 | #baz #quux {}
|
70 | ```
|
71 |
|
72 |
|
73 | ```css
|
74 | /* `#bar` is inside `:not()`, so it is evaluated separately */
|
75 | #foo #bar:not(#baz) {}
|
76 | ```
|