UNPKG

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