1 | # selector-max-type
|
2 |
|
3 | Limit the number of type selectors in a selector.
|
4 |
|
5 |
|
6 | ```css
|
7 | a {}
|
8 | /** ↑
|
9 | * This type of selector */
|
10 | ```
|
11 |
|
12 | This rule resolves nested selectors before counting the number of type 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 type selectors allowed.
|
19 |
|
20 | For example, with `2`:
|
21 |
|
22 | The following patterns are considered violations:
|
23 |
|
24 |
|
25 | ```css
|
26 | div a span {}
|
27 | ```
|
28 |
|
29 |
|
30 | ```css
|
31 | div a {
|
32 | & span {}
|
33 | }
|
34 | ```
|
35 |
|
36 |
|
37 | ```css
|
38 | div a {
|
39 | & > a {}
|
40 | }
|
41 | ```
|
42 |
|
43 | The following patterns are _not_ considered violations:
|
44 |
|
45 |
|
46 | ```css
|
47 | div {}
|
48 | ```
|
49 |
|
50 |
|
51 | ```css
|
52 | div a {}
|
53 | ```
|
54 |
|
55 |
|
56 | ```css
|
57 | .foo div a {}
|
58 | ```
|
59 |
|
60 |
|
61 | ```css
|
62 | div.foo a {}
|
63 | ```
|
64 |
|
65 |
|
66 | ```css
|
67 | /* each selector in a selector list is evaluated separately */
|
68 | div,
|
69 | a span {}
|
70 | ```
|
71 |
|
72 |
|
73 | ```css
|
74 | /* `span` is inside `:not()`, so it is evaluated separately */
|
75 | div a .foo:not(span) {}
|
76 | ```
|
77 |
|
78 | ## Optional secondary options
|
79 |
|
80 | ### `ignore: ["child", "compounded", "descendant", "next-sibling"]`
|
81 |
|
82 | #### `"child"`
|
83 |
|
84 | Discount child type selectors.
|
85 |
|
86 | For example, with `2`:
|
87 |
|
88 | The following patterns are _not_ considered violations:
|
89 |
|
90 |
|
91 | ```css
|
92 | div span > a {}
|
93 | ```
|
94 |
|
95 |
|
96 | ```css
|
97 | #bar div span > a {}
|
98 | ```
|
99 |
|
100 | #### `"compounded"`
|
101 |
|
102 | Discount compounded type selectors -- i.e. type selectors chained with other selectors.
|
103 |
|
104 | For example, with `2`:
|
105 |
|
106 | The following patterns are _not_ considered violations:
|
107 |
|
108 |
|
109 | ```css
|
110 | div span a.foo {}
|
111 | ```
|
112 |
|
113 |
|
114 | ```css
|
115 | div span a#bar {}
|
116 | ```
|
117 |
|
118 | #### `"descendant"`
|
119 |
|
120 | Discount descendant type selectors.
|
121 |
|
122 | For example, with `2`:
|
123 |
|
124 | The following patterns are _not_ considered violations:
|
125 |
|
126 |
|
127 | ```css
|
128 | .foo div span a {}
|
129 | ```
|
130 |
|
131 |
|
132 | ```css
|
133 | #bar div span a {}
|
134 | ```
|
135 |
|
136 | #### `"next-sibling"`
|
137 |
|
138 | Discount next-sibling type selectors.
|
139 |
|
140 | For example, with `2`:
|
141 |
|
142 | The following patterns are _not_ considered violations:
|
143 |
|
144 |
|
145 | ```css
|
146 | div a + span {}
|
147 | ```
|
148 |
|
149 |
|
150 | ```css
|
151 | #bar + div + span + a + span {}
|
152 | ```
|
153 |
|
154 | ### `ignoreTypes: ["/regex/", /regex/, "string"]`
|
155 |
|
156 | Given:
|
157 |
|
158 | ```
|
159 | ["/^my-/", "custom"]
|
160 | ```
|
161 |
|
162 | For example, with `2`.
|
163 |
|
164 | The following patterns are _not_ considered violations:
|
165 |
|
166 |
|
167 | ```css
|
168 | div a custom {}
|
169 | ```
|
170 |
|
171 |
|
172 | ```css
|
173 | div a my-type {}
|
174 | ```
|
175 |
|
176 |
|
177 | ```css
|
178 | div a my-other-type {}
|
179 | ```
|