Bug 1789787 - Update ujson version for web-platform-tests, r=glandium
[gecko.git] / .stylelintrc.js
blob0c80c07c8fa81603cec8f7abd07720982b1e9119
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* eslint-env node */
7 "use strict";
9 const fs = require("fs");
10 const path = require("path");
12 function readFile(path) {
13   return fs
14     .readFileSync(path, { encoding: "utf-8" })
15     .split("\n")
16     .filter(p => p && !p.startsWith("#"));
19 const ignoreFiles = [
20   ...readFile(
21     path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
22   ),
23   ...readFile(path.join(__dirname, "tools", "rewriting", "Generated.txt")),
26 module.exports = {
27   extends: ["stylelint-config-recommended"],
28   ignoreFiles,
29   rules: {
30     /* Disabled because of `-moz-element(#foo)` which gets misparsed. */
31     "color-no-invalid-hex": null,
32     "font-family-no-missing-generic-family-keyword": [
33       true,
34       {
35         ignoreFontFamilies: [
36           "-moz-button",
37           "-moz-field",
38           "-moz-fixed",
39           "-moz-list",
40           "caption",
41         ],
42       },
43     ],
45     "function-no-unknown": [
46       true,
47       {
48         ignoreFunctions: [
49           "-moz-image-rect" /* Used for cropping images */,
50           "add" /* Used in mathml.css */,
51         ],
52       },
53     ],
55     "no-descending-specificity": null,
56     "no-duplicate-selectors": null,
58     "property-no-unknown": [
59       true,
60       {
61         ignoreProperties: ["overflow-clip-box"],
62       },
63     ],
65     /*
66      * XXXgijs: we would like to enable this, but we can't right now.
67      * This is because Gecko uses a number of custom pseudoclasses,
68      * and stylelint assumes that for `:unknown-pseudoclass(foo)`,
69      * `foo` should be a known type.
70      * This is tedious but workable for things like `-moz-locale-dir` where
71      * the set of acceptable values (ltr/rtl) is small.
72      * However, for tree cells, the set of values is unlimited (ie
73      * user-defined, based on atoms sent by the JS tree view APIs).
74      * There does not appear to be a way to exempt the contents of these
75      * unknown pseudoclasses, and as a result, this rule is not
76      * usable for us. The 'type' only includes the contents of the
77      * pseudoclass, not the pseudo itself, so we can't filter based on the
78      * pseudoclass either.
79      * Ideally, we would either create an option to the builtin rule
80      * in stylelint itself, or mimic the rule but exempt these, or
81      * add parser support for our custom pseudoclasses.
82      *
83      * For now, we just disable this rule.
84      */
85     "selector-type-no-unknown": null,
86     /*
87      * See above - if we enabled this rule, we'd have to allow for a number
88      * of custom elements we use, which are listed here:
89     "selector-type-no-unknown": [
90       true,
91       {
92         ignore: ["custom-elements"],
93         ignoreTypes: [
94           // Modern custom element / storybooked components:
95           /^moz-/,
96           // moz-locale-dir trips this rule for some reason:
97           "rtl",
98           "ltr",
99           // Migrated XBL elements not part of core XUL that we use at the moment:
100           "findbar",
101           "panelmultiview",
102           "panelview",
103           "popupnotification",
104           "popupnotificationcontent",
105           // Legacy XUL elements:
106           // (the commented out ones used to be a thing and aren't used in-tree anymore)
107           "arrowscrollbox",
108           "box",
109           // "broadcaster",
110           // "broadcasterset",
111           "button",
112           "browser",
113           "checkbox",
114           "caption",
115           // clicktoscroll
116           // colorpicker
117           // column
118           // columns
119           "commandset",
120           "command",
121           // conditions
122           // content
123           // datepicker
124           "deck",
125           "description",
126           "dialog",
127           // dialogheader
128           "dropmarker",
129           "editor",
130           // grid
131           // grippy
132           "groupbox",
133           "hbox",
134           // iframe
135           // image
136           "key",
137           "keyset",
138           // label
139           "listbox",
140           // listcell
141           // listcol
142           // listcols
143           // listhead
144           // listheader
145           "listitem",
146           // member
147           "menu",
148           "menubar",
149           "menucaption",
150           "menuitem",
151           "menulist",
152           "menupopup",
153           "menuseparator",
154           "notification",
155           "notificationbox",
156           "observes",
157           // overlay
158           // page
159           "panel",
160           // param
161           "popupset",
162           // preference
163           // preferences
164           // prefpane
165           // prefwindow
166           // progressmeter
167           // query
168           // queryset
169           "radio",
170           "radiogroup",
171           // resizer
172           "richlistbox",
173           "richlistitem",
174           // row
175           // rows
176           // rule
177           // scale
178           // script
179           "scrollbar",
180           "scrollbox",
181           "scrollcorner",
182           "separator",
183           "spacer",
184           // spinbuttons
185           "splitter",
186           "stack",
187           // statusbar
188           // statusbarpanel
189           "stringbundle",
190           "stringbundleset",
191           "tab",
192           "tabbox",
193           "tabpanel",
194           "tabpanels",
195           "tabs",
196           // template
197           // textnode
198           "textbox",
199           // timepicker
200           "titlebar",
201           "toolbar",
202           "toolbarbutton",
203           // toolbargrippy
204           "toolbaritem",
205           "toolbarpalette",
206           "toolbarpaletteitem",
207           "toolbarseparator",
208           "toolbarset",
209           "toolbarspacer",
210           "toolbarspring",
211           "toolbartabstop",
212           "toolbox",
213           "tooltip",
214           "tree",
215           "treecell",
216           "treechildren",
217           "treecol",
218           "treecols",
219           "treeitem",
220           "treerow",
221           "treeseparator",
222           // triple
223           "vbox",
224           // where
225           "window",
226           "wizard",
227           "wizardpage",
228         ],
229       },
230     ],
231     */
233     "selector-pseudo-class-no-unknown": [
234       true,
235       {
236         ignorePseudoClasses: ["popover-open"],
237       },
238     ],
239   },
241   overrides: [
242     {
243       files: "*.scss",
244       customSyntax: "postcss-scss",
245       extends: "stylelint-config-recommended-scss",
246     },
247     {
248       files: "browser/components/newtab/**",
249       customSyntax: "postcss-scss",
250       extends: "stylelint-config-standard-scss",
251       rules: {
252         "at-rule-disallowed-list": [
253           ["debug", "warn", "error"],
254           {
255             message: "Clean up %s directives before committing",
256           },
257         ],
258         "at-rule-no-vendor-prefix": null,
259         "color-function-notation": null,
260         "color-hex-case": "upper",
261         "comment-empty-line-before": [
262           "always",
263           {
264             except: ["first-nested"],
265             ignore: ["after-comment", "stylelint-commands"],
266           },
267         ],
268         "custom-property-empty-line-before": null,
269         "custom-property-pattern": null,
270         "declaration-block-no-duplicate-properties": true,
271         "declaration-block-no-redundant-longhand-properties": null,
272         "declaration-no-important": true,
273         "function-no-unknown": [
274           true,
275           {
276             ignoreFunctions: ["div"],
277           },
278         ],
279         "function-url-no-scheme-relative": true,
280         indentation: 2,
281         "keyframes-name-pattern": null,
282         "max-nesting-depth": [
283           8,
284           {
285             ignore: ["blockless-at-rules", "pseudo-classes"],
286           },
287         ],
288         "media-feature-name-no-vendor-prefix": null,
289         "no-descending-specificity": null,
290         "no-eol-whitespace": true,
291         "no-missing-end-of-source-newline": true,
292         "number-leading-zero": "always",
293         "number-no-trailing-zeros": true,
294         "property-disallowed-list": [
295           ["margin-left", "margin-right"],
296           {
297             message: "Use margin-inline instead of %s",
298           },
299         ],
300         "property-no-unknown": true,
301         "property-no-vendor-prefix": null,
302         "scss/dollar-variable-empty-line-before": null,
303         "scss/double-slash-comment-empty-line-before": [
304           "always",
305           {
306             except: ["first-nested"],
307             ignore: ["between-comments", "stylelint-commands", "inside-block"],
308           },
309         ],
310         "selector-class-pattern": null,
311         "selector-no-vendor-prefix": null,
312         "string-quotes": [
313           "single",
314           {
315             avoidEscape: true,
316           },
317         ],
318         "value-keyword-case": null,
319         "value-no-vendor-prefix": null,
320       },
321     },
322   ],