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