forked from mozilla-firefox/firefox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.stylelintrc.js
More file actions
474 lines (460 loc) · 14.5 KB
/
.stylelintrc.js
File metadata and controls
474 lines (460 loc) · 14.5 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env node */
"use strict";
const fs = require("fs");
const path = require("path");
const rollouts = require("./stylelint-rollouts.config");
function readFile(filePath) {
return fs
.readFileSync(filePath, { encoding: "utf-8" })
.split("\n")
.filter(p => p && !p.startsWith("#"));
}
const ignoreFiles = [
...readFile(
path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
),
...readFile(path.join(__dirname, "tools", "rewriting", "Generated.txt")),
];
module.exports = {
extends: ["stylelint-config-recommended"],
plugins: [
"./tools/lint/stylelint/stylelint-plugin-mozilla/index.mjs",
"@stylistic/stylelint-plugin",
"stylelint-use-logical",
],
ignoreFiles,
rules: {
/* Disabled because of `-moz-element(#foo)` which gets misparsed. */
"color-no-invalid-hex": null,
"font-family-no-missing-generic-family-keyword": [
true,
{
ignoreFontFamilies: [
"-moz-button",
"-moz-field",
"-moz-fixed",
"-moz-list",
"caption",
],
},
],
"function-no-unknown": [
true,
{
ignoreFunctions: [
"light-dark" /* Used for color-scheme dependent colors */,
"add" /* Used in mathml.css */,
"-moz-symbolic-icon" /* Used for GTK icons */,
],
},
],
"length-zero-no-unit": [
true,
{
ignore: ["custom-properties"],
},
],
"max-nesting-depth": [
3,
{
ignore: ["blockless-at-rules"],
},
],
"no-descending-specificity": null,
"no-duplicate-selectors": null,
"property-no-unknown": [
true,
{
ignoreProperties: [
// overflow-clip-box is Gecko-specific and not exposed to web
// content. Might be replaced with overflow-clip-margin, see:
// https://github.com/w3c/csswg-drafts/issues/10745
"overflow-clip-box",
"overflow-clip-box-block",
"overflow-clip-box-inline",
],
},
],
/*
* XXXgijs: we would like to enable this, but we can't right now.
* This is because Gecko uses a number of custom pseudoclasses,
* and stylelint assumes that for `:unknown-pseudoclass(foo)`,
* `foo` should be a known type.
* This is tedious but workable for things like `-moz-locale-dir` where
* the set of acceptable values (ltr/rtl) is small.
* However, for tree cells, the set of values is unlimited (ie
* user-defined, based on atoms sent by the JS tree view APIs).
* There does not appear to be a way to exempt the contents of these
* unknown pseudoclasses, and as a result, this rule is not
* usable for us. The 'type' only includes the contents of the
* pseudoclass, not the pseudo itself, so we can't filter based on the
* pseudoclass either.
* Ideally, we would either create an option to the builtin rule
* in stylelint itself, or mimic the rule but exempt these, or
* add parser support for our custom pseudoclasses.
*
* For now, we just disable this rule.
*/
"selector-type-no-unknown": null,
/*
* See above - if we enabled this rule, we'd have to allow for a number
* of custom elements we use, which are listed here:
"selector-type-no-unknown": [
true,
{
ignore: ["custom-elements"],
ignoreTypes: [
// Modern custom element / storybooked components:
/^moz-/,
// moz-locale-dir trips this rule for some reason:
"rtl",
"ltr",
// Migrated XBL elements not part of core XUL that we use at the moment:
"findbar",
"panelmultiview",
"panelview",
"popupnotification",
"popupnotificationcontent",
// Legacy XUL elements:
// (the commented out ones used to be a thing and aren't used in-tree anymore)
"arrowscrollbox",
"box",
// "broadcaster",
// "broadcasterset",
"button",
"browser",
"checkbox",
"caption",
// clicktoscroll
// colorpicker
// column
// columns
"commandset",
"command",
// conditions
// content
// datepicker
"deck",
"description",
"dialog",
// dialogheader
"dropmarker",
"editor",
// grid
// grippy
"groupbox",
"hbox",
// iframe
// image
"key",
"keyset",
// label
"listbox",
// listcell
// listcol
// listcols
// listhead
// listheader
"listitem",
// member
"menu",
"menubar",
"menucaption",
"menuitem",
"menulist",
"menupopup",
"menuseparator",
"notification",
"notificationbox",
"observes",
// overlay
// page
"panel",
// param
"popupset",
// preference
// preferences
// prefpane
// prefwindow
// progressmeter
// query
// queryset
"radio",
"radiogroup",
// resizer
"richlistbox",
"richlistitem",
// row
// rows
// rule
// scale
// script
"scrollbar",
"scrollbox",
"scrollcorner",
"separator",
"spacer",
// spinbuttons
"splitter",
"stack",
// statusbar
// statusbarpanel
"stringbundle",
"stringbundleset",
"tab",
"tabbox",
"tabpanel",
"tabpanels",
"tabs",
// template
// textnode
"textbox",
// timepicker
"titlebar",
"toolbar",
"toolbarbutton",
// toolbargrippy
"toolbaritem",
"toolbarpalette",
"toolbarpaletteitem",
"toolbarseparator",
"toolbarset",
"toolbarspacer",
"toolbarspring",
"toolbartabstop",
"toolbox",
"tooltip",
"tree",
"treecell",
"treechildren",
"treecol",
"treecols",
"treeitem",
"treerow",
"treeseparator",
// triple
"vbox",
// where
"window",
"wizard",
"wizardpage",
],
},
],
*/
"selector-pseudo-class-no-unknown": [
true,
{
ignorePseudoClasses: ["popover-open"],
},
],
"selector-pseudo-element-no-unknown": [
true,
{
ignorePseudoElements: ["slider-track", "slider-fill", "slider-thumb"],
},
],
// stylelint fixes for the use-logical rule will be addressed in Bug 1996168
// Remove this line setting `csscontrols/use-logical` to null after implementing fixes
"csstools/use-logical": null,
"stylelint-plugin-mozilla/no-base-design-tokens": true,
"stylelint-plugin-mozilla/use-design-tokens": true,
"stylelint-plugin-mozilla/no-non-semantic-token-usage": true,
},
overrides: [
{
files: "*.scss",
customSyntax: "postcss-scss",
extends: "stylelint-config-recommended-scss",
},
{
files: [
"browser/components/aboutwelcome/**",
"browser/components/asrouter/**",
"browser/extensions/newtab/**",
],
customSyntax: "postcss-scss",
extends: "stylelint-config-standard-scss",
rules: {
"@stylistic/color-hex-case": "upper",
"@stylistic/indentation": 2,
"@stylistic/no-eol-whitespace": true,
"@stylistic/no-missing-end-of-source-newline": true,
"@stylistic/number-leading-zero": "always",
"@stylistic/number-no-trailing-zeros": true,
"@stylistic/string-quotes": [
"single",
{
avoidEscape: true,
},
],
"at-rule-disallowed-list": [
["debug", "warn", "error"],
{
message: "Clean up %s directives before committing",
},
],
"at-rule-no-vendor-prefix": null,
"color-function-notation": null,
"comment-empty-line-before": [
"always",
{
except: ["first-nested"],
ignore: ["after-comment", "stylelint-commands"],
},
],
"custom-property-empty-line-before": null,
"custom-property-pattern": null,
"declaration-block-no-duplicate-properties": true,
"declaration-block-no-redundant-longhand-properties": null,
"declaration-no-important": true,
"function-no-unknown": [
true,
{
ignoreFunctions: ["div"],
},
],
"function-url-no-scheme-relative": true,
"keyframes-name-pattern": null,
"media-feature-name-no-vendor-prefix": null,
"no-descending-specificity": null,
"property-disallowed-list": [
["margin-left", "margin-right"],
{
message: "Use margin-inline instead of %s",
},
],
"property-no-unknown": true,
"property-no-vendor-prefix": null,
"scss/dollar-variable-empty-line-before": null,
"scss/double-slash-comment-empty-line-before": [
"always",
{
except: ["first-nested"],
ignore: ["between-comments", "stylelint-commands", "inside-block"],
},
],
"selector-class-pattern": null,
"selector-no-vendor-prefix": null,
"value-keyword-case": null,
"value-no-vendor-prefix": null,
},
},
{
files: ["browser/extensions/newtab/**"],
rules: {
"declaration-property-value-disallowed-list": [
{
"font-size": [
"/^[0-9.]+(px|em|rem|%)$/",
"/^[0-9.]+$/",
"/^(small|medium|large|x-large|xx-large)$/",
],
"border-radius": [
"/^[0-9.]+(px|em|rem|%)$/",
"/^(small|medium|large|x-large|xx-large)$/",
],
// Validate to only allow variables and global values
"font-weight": [
"/^(?!var\\(|inherit$|initial$|unset$|revert$|revert-layer$).+$/",
],
[/^(margin|padding|inset|gap|row-gap|column-gap|grid-row-gap|grid-column-gap|top|right|bottom|left)($|-)/]:
["/[0-9.]+(px|em|rem)|\\$/"],
},
{
message:
"Avoid literal values. Use variables (e.g. var(--font-size-small)) or inherit/unset/etc.",
},
],
"csstools/use-logical": [
"always",
{
// Bug 2003301: Do not enforce logical properties for any height/width properties
except: [/^(min-|max-)?width/i, /^(min-|max-)?height/i],
severity: "error",
},
],
},
},
{
name: "design-token-rules-off",
files: [
// CSS files under browser/branding do not use design tokens
"browser/branding/**",
// CSS files under browser/components/extensions are not using design tokens
"browser/components/extensions/**",
// Webcompat interventions are not expected to use design tokens
// They are intended to override existing styles for specific extension
"browser/extensions/webcompat/injections/css/**",
// Most of devtools does not use design tokens, so turn the appropriate rules off for devtools.
// Stylelint does not support negating the file glob within an overrides section,
// so these rules get re-enabled for some devtools files in the section below
"devtools/**",
// FXR is no longer maintained and is not expected to use design tokens
"browser/fxr/**",
// Android does not use design tokens
"mobile/android/**",
// Docs do not use design tokens
"docs/**",
// DOM does not use design tokens
"dom/**",
// Layouts do not use design tokens
"layout/**",
// Testing does not use design tokens
"testing/**",
// UA Widgets should not use design tokens
"toolkit/themes/shared/colorpicker-common.css",
"toolkit/themes/shared/colorpicker.css",
"toolkit/themes/shared/media/pipToggle.css",
"toolkit/themes/shared/media/videocontrols.css",
"toolkit/content/widgets/datetimebox.css",
"toolkit/content/widgets/marquee.css",
"toolkit/themes/shared/media/textrecognition.css",
// The contents of backup/content/archive.css are injected as inline CSS
// into the HTML backup archive files that exist on a user's file system
// and can be opened in any browser.
"browser/components/backup/content/archive.css",
// Bug 2003877 - this is a centralization of a bunch of rules that had
// been spread across about:newtab and about:privatebrowsing. We'll
// fix these design tokens issues in a follow-up (presuming the
// replacement of the handoff bar doesn't land and remove this first).
"browser/components/search/content/contentSearchHandoffUI.css",
],
rules: {
"stylelint-plugin-mozilla/use-design-tokens": null,
"stylelint-plugin-mozilla/no-non-semantic-token-usage": null,
},
},
{
name: "design-token-rules-on",
files: [
// Enable design token related rules only on the parts of devtools that can use them
"devtools/client/aboutdebugging/src/**",
],
rules: {
"stylelint-plugin-mozilla/use-design-tokens": true,
"stylelint-plugin-mozilla/no-non-semantic-token-usage": true,
},
},
{
files: ["toolkit/**/*.css", "toolkit/**/*.scss"],
rules: {
"stylelint-plugin-mozilla/no-browser-refs-in-toolkit": true,
},
},
{
// non-logical properties make sense in devtools/ where physical positioning always makes sense
name: "logical-properties-rule-off",
files: ["devtools/**"],
rules: {
"csstools/use-logical": null,
},
},
// Rollouts should always be applied last in the overrides section
// to ensure that they take precedence over other overrides.
...rollouts,
],
};