-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlinthtmlwithcss.css
289 lines (214 loc) · 7.57 KB
/
linthtmlwithcss.css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* lintHTMLwithCSS */
:root {
--lint: 2px dashed red;
}
/* Debug inputs and labels without id or for attribute */
/* Are you sure your code is ok? Explicit relation between an input and its label is always better. Use id and for attributes to do so. */
/* By Geoffrey Crofte */
input:not([id], label:not([for])) {
outline: var(--lint);
content: "Debug inputs and labels without id or for attribute";
}
/* Links go nowhere? */
/* This selector hunts for links that have:
- No href
- an empty href
- a "#" href (button perhaps?) */
/* By Adam Argyle */
a:is(:not([href]), [href=""], [href="#"]) {
outline: var(--lint);
content: "This selector hunts for links that have No href, an empty href and a '#' href";
}
/* Image without alt attribute? */
/* Debug images without alt attribute with CSS. */
/* By Geoffrey Crofte */
img:not([alt]) {
outline: var(--lint);
content: "Debug images without alt attribute with CSS.";
}
/* This selector hunts for forbidden nesting */
/* By Adam Argyle */
:not(figure) > figcaption,
:not(fieldset) > legend,
:not(dl) > :is(dt, dd),
:not(tr) > :is(td, th),
:not(select) > :is(option, optgroup),
:not(table) > :is(thead, tfoot, tbody, tr, colgroup, caption) {
outline: var(--lint);
content: "This selector hunts for forbidden nesting";
}
/* Only <li>'s allowed here! */
/* This selector hunts for lists that have something other than an <li> inside */
/* By Adam Argyle */
:is(ul, ol) > :not(li) {
outline: var(--lint);
content: "This selector hunts for lists that have something other than an <li> inside";
}
/* this selector hunts for elements with a tabindex other than 0 or -1 */
/* values other than 0 or -1 can steal or disrupt natural tab order and is generally something to avoid */
/* By Adam Argyle */
[tabindex]:not([tabindex="0"], [tabindex="-1"]) {
outline: var(--lint);
content: "This selector hunts for elements with a tabindex other than 0 or -1";
}
/* Debugs buttons without type attribute, with CSS */
/* Non-explicit type leads to button being a submit button. Not all buttons are submit buttons. A neutral type would be type="button" */
/* By Adam Argyle */
button:not([type]) {
outline: var(--lint);
content: "Debugs buttons without type attribute";
}
/* Find all the input fields without any labelling */
/* By Tanisha Sabherwal */
input:not([type="button"])
:not([type="reset"])
:not([type="submit"])
:not([aria-labelledby],[id]),
textarea:not([aria-labelledby],[id])
label:not([for]) {
outline: var(--lint);
content: "Find all the input fields without any labelling";
}
/* Find all the buttons without any label */
/* By Tanisha Sabherwal */
input[type=button]:not([aria-label]),
input[type=reset]:not([aria-label]),
input[type=submit]:not([aria-label]),
button:not([aria-label]) {
outline: var(--lint);
content: "Find all the buttons without any label";
}
/* Tables should have a caption */
/* This one is useful to force each <caption> to be the first direct child of a <table> elements. */
/* By Quentin Bellanger */
table > *:first-child:not(caption) {
outline: var(--lint);
content: "Tables should have a caption";
}
/* Headers out of order (i.e. h2 before h1, etc.) */
/* By Una Kravets */
h2 ~ h1,
h3 ~ h1,
h4 ~ h1,
h5 ~ h1,
h6 ~ h1,
h3 ~ h2:first-of-type,
h4 ~ h2:first-of-type,
h5 ~ h2:first-of-type,
h6 ~ h2:first-of-type,
h4 ~ h3:first-of-type,
h5 ~ h3:first-of-type,
h6 ~ h3:first-of-type,
h5 ~ h4:first-of-type,
h6 ~ h4:first-of-type,
h6 ~ h5:first-of-type {
outline: var(--lint);
content: "Headers out of order (i.e. h2 before h1, etc.)";
}
/* Find <picture> elements that don't contain a WebP <source> */
/* By Jay Holtslander */
picture > source:first-child:not([type="image/webp"]):before {
outline: var(--lint);
content: "Find <picture> elements that don't contain a WebP <source>";
}
/* <img> and <iframe>'s without native lazy loading */
/* By Jay Holtslander */
img:not([loading="lazy"]),
iframe:not([loading="lazy"]) {
outline: var(--lint);
content: "<img> and <iframe>'s without native lazy loading";
}
/* Prevents the absence of lang attribute */
/* By Geoffrey Crofte */
html:not([lang])::before {
outline: var(--lint);
content: "Prevents the absence of lang attribute";
}
/* SVG without focusable=false when decorative or hidden */
/* By Geoffrey Crofte */
svg:is([role="presentation"], [aria-label], [aria-labelledby], [aria-hidden="true"]):not([focusable="false"]) {
outline: var(--lint);
content: "SVG without focusable=false when decorative or hidden";
}
/* Mismatched [dir] && [lang] */
/* By Adam Argyle */
[dir="rtl"]:not([lang="ar"], [lang="he"]),
:is([lang="ar"], [lang="he"]):not([dir="rtl"]),
:is([lang="ar"], [lang="he"]) [lang]:not([dir="ltr"]) {
outline: var(--lint);
content: "Mismatched [dir] && [lang]";
}
/* SVG without title or aria-label and not considered as decorative */
/* By Geoffrey Crofte */
svg:not([role="presentation"]):not([aria-label]):not([aria-labelledby]) > :first-child:not(title) {
outline: var(--lint);
content: "SVG without title or aria-label and not considered as decorative";
}
/* Insecure [target=blank] */
/* By Adam Argyle */
[target$="blank"]:not(
[rel],
[rel*="noopener"],
[rel*="noreferrer"]
) {
outline: var(--lint);
content: "Insecure [target=blank]";
}
/* Summary must be the first child */
/* By Adam Argyle */
details > summary:not(:first-child),
details > *:first-child:not(summary) {
outline: var(--lint);
content: "Summary must be the first child";
}
/* Fieldset where legend isn't the first child */
/* By Geoffrey Crofte */
fieldset > :first-child:not(legend)::before {
outline: var(--lint);
content: 'add a <legend> first, please';
}
/* No divs inside inline elements */
/* By Adam Argyle */
:is(b,i,q,em,abbr,cite,code,span,small,label,strong) > div {
outline: var(--lint);
content: "No divs inside inline elements";
}
/* No headings inside inline <a> tag */
/* By Tanisha Sabherwal */
a h1,
a h2,
a h3,
a h4,
a h5,
a h6 {
outline: var(--lint);
content: "No headings inside inline <a> tag";
}
/* <img> without height and width that will cause cumulative layout shift. See: https://web.dev/optimize-cls/#images-without-dimensions */
/* By Jay Holtslander */
img:not([width]),
img:not([height]) {
outline: var(--lint);
content: "<img> without height and width that will cause cumulative layout shift. See: https://web.dev/optimize-cls/#images-without-dimensions";
}
/* <embeds> or <iframes> without height and width that will cause cumulative layout shift. See: https://web.dev/optimize-cls/#ads-embeds-and-iframes-without-dimensions */
/* By Jay Holtslander */
embed:not([width]),
iframe:not([height]) {
outline: var(--lint);
content: "<embeds> or <iframes> without height and width that will cause cumulative layout shift. See: https://web.dev/optimize-cls/#ads-embeds-and-iframes-without-dimensions";
}
/* Not utilizing srcset for responsive images. See: https://html.com/attributes/img-srcset/ */
/* By Jay Holtslander */
img:not([srcset]) {
outline: var(--lint);
content: "Not utilizing srcset for responsive images. See: https://html.com/attributes/img-srcset/";
}
/* Empty buttons or links without any kind of labelling */
/* By Geoffrey Crofte */
:is(button, a):empty:not([aria-label]):not([aria-labelledby]),
:is(button, a):not([aria-label]):not([aria-labelledby]) img:only-child:is(:not([alt]),[alt=""]),
:is(button, a):not([aria-label]):not([aria-labelledby]) i:only-child:not([aria-label]):not([aria-labelledby]) {
outline: var(--lint);
content: "Empty buttons or links without any kind of labelling";
}