Bug 1779434 [wpt PR 34835] - Reserve the default keyword from <custom-ident> CSS...
[gecko.git] / .eslintrc.js
blobd97b0a93951afaebf27e820daed05ddac35078cb
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 "use strict";
7 const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
8 const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
9 const mochitestTestConfig = require("eslint-plugin-mozilla/lib/configs/mochitest-test.js");
10 const chromeTestConfig = require("eslint-plugin-mozilla/lib/configs/chrome-test.js");
11 const fs = require("fs");
12 const path = require("path");
14 /**
15  * Some configurations have overrides, which can't be specified within overrides,
16  * so we need to remove them.
17  */
18 function removeOverrides(config) {
19   config = { ...config };
20   delete config.overrides;
21   return config;
24 // The expressions defined below for test paths are the main path formats we
25 // prefer to support for tests as they are commonly used across the tree.
26 // See https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint.html#i-m-adding-tests-how-do-i-set-up-the-right-configuration
27 // for more information.
29 const xpcshellTestPaths = [
30   "**/test*/unit*/**/",
31   "**/test*/*/unit*/",
32   "**/test*/xpcshell/**/",
35 const browserTestPaths = ["**/test*/**/browser*/"];
37 const mochitestTestPaths = [
38   // Note: we do not want to match testing/mochitest as that would apply
39   // too many globals for that directory.
40   "**/test/mochitest/",
41   "**/tests/mochitest/",
42   "**/test/mochitests/",
43   "testing/mochitest/tests/SimpleTest/",
44   "testing/mochitest/tests/Harness_sanity/",
47 const chromeTestPaths = ["**/test*/chrome/"];
49 const ignorePatterns = [
50   ...fs
51     .readFileSync(
52       path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
53     )
54     .toString("utf-8")
55     .split("\n"),
56   ...fs
57     .readFileSync(
58       path.join(
59         __dirname,
60         "devtools",
61         "client",
62         "debugger",
63         "src",
64         ".eslintignore"
65       )
66     )
67     .toString("utf-8")
68     .split("\n")
69     .filter(p => p && !p.startsWith("#"))
70     .map(p => `devtools/client/debugger/src/${p}`),
73 module.exports = {
74   parser: "@babel/eslint-parser",
75   parserOptions: {
76     sourceType: "script",
77     babelOptions: {
78       configFile: path.join(__dirname, ".babel-eslint.rc.js"),
79     },
80   },
81   settings: {
82     "import/extensions": [".mjs"],
83   },
84   ignorePatterns,
85   // Ignore eslint configurations in parent directories.
86   root: true,
87   // New rules and configurations should generally be added in
88   // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
89   // allow external repositories that use the plugin to pick them up as well.
90   extends: ["plugin:mozilla/recommended"],
91   plugins: ["mozilla", "import"],
92   overrides: [
93     {
94       // All .eslintrc.js files are in the node environment, so turn that
95       // on here.
96       // https://github.com/eslint/eslint/issues/13008
97       files: [".eslintrc.js"],
98       env: {
99         node: true,
100         browser: false,
101       },
102     },
103     {
104       files: ["*.mjs"],
105       rules: {
106         "import/default": "error",
107         "import/export": "error",
108         "import/named": "error",
109         "import/namespace": "error",
110         "import/newline-after-import": "error",
111         "import/no-anonymous-default-export": "error",
112         "import/no-duplicates": "error",
113         "import/no-absolute-path": "error",
114         "import/no-named-default": "error",
115         "import/no-named-as-default": "error",
116         "import/no-named-as-default-member": "error",
117         "import/no-self-import": "error",
118         "import/no-unassigned-import": "error",
119         "import/no-unresolved": "error",
120         "import/no-useless-path-segments": "error",
121       },
122     },
123     {
124       files: [
125         // Bug 1773473 - Turn off no-unresolved for system mjs modules, as we
126         // do not yet have a resolver for resource:// uris.
127         "*.sys.mjs",
128         // Bug 1773475 - For now, turn off no-unresolved on some paths where we import
129         // from node_modules, as the ESLint setup only installs modules at the
130         // top-level.
131         "devtools/shared/compatibility/**",
132       ],
133       rules: {
134         "import/no-unresolved": "off",
135       },
136     },
137     {
138       files: [
139         "*.html",
140         "*.xhtml",
141         "*.xml",
142         "js/src/builtin/**/*.js",
143         "js/src/shell/**/*.js",
144       ],
145       rules: {
146         // Curly brackets are required for all the tree via recommended.js,
147         // however these files aren't auto-fixable at the moment.
148         curly: "off",
149       },
150     },
151     {
152       // TODO: Bug 1515949. Enable no-undef for gfx/
153       files: "gfx/layers/apz/test/mochitest/**",
154       rules: {
155         "no-undef": "off",
156       },
157     },
158     {
159       ...removeOverrides(xpcshellTestConfig),
160       files: xpcshellTestPaths.map(path => `${path}**`),
161       excludedFiles: "devtools/**",
162     },
163     {
164       // If it is an xpcshell head file, we turn off global unused variable checks, as it
165       // would require searching the other test files to know if they are used or not.
166       // This would be expensive and slow, and it isn't worth it for head files.
167       // We could get developers to declare as exported, but that doesn't seem worth it.
168       files: xpcshellTestPaths.map(path => `${path}head*.js`),
169       rules: {
170         "no-unused-vars": [
171           "error",
172           {
173             args: "none",
174             vars: "local",
175           },
176         ],
177       },
178     },
179     {
180       // This section enables warning of no-unused-vars globally for all test*.js
181       // files in xpcshell test paths.
182       // These are turned into errors with selected exclusions in the next
183       // section.
184       // Bug 1612907: This section should go away once the exclusions are removed
185       // from the following section.
186       files: xpcshellTestPaths.map(path => `${path}test*.js`),
187       rules: {
188         // No declaring variables that are never used
189         "no-unused-vars": [
190           "warn",
191           {
192             args: "none",
193             vars: "all",
194           },
195         ],
196       },
197     },
198     {
199       // This section makes global issues with no-unused-vars be reported as
200       // errors - except for the excluded lists which are being fixed in the
201       // dependencies of bug 1612907.
202       files: xpcshellTestPaths.map(path => `${path}test*.js`),
203       excludedFiles: [
204         // These are suitable as good first bugs, take one or two related lines
205         // per bug.
206         "caps/tests/unit/test_origin.js",
207         "extensions/permissions/**",
208         "image/test/unit/**",
209         "intl/uconv/tests/unit/test_bug340714.js",
210         "modules/libjar/test/unit/test_empty_jar_telemetry.js",
211         "modules/libjar/zipwriter/test/unit/test_alignment.js",
212         "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
213         "modules/libjar/zipwriter/test/unit/test_storedata.js",
214         "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
215         "modules/libpref/test/unit/test_dirtyPrefs.js",
216         "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
217         "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
219         // These are more complicated bugs which may require some in-depth
220         // investigation or different solutions. They are also likely to be
221         // a reasonable size.
222         "browser/components/**",
223         "browser/modules/**",
224         "dom/**",
225         "netwerk/**",
226         "security/manager/ssl/tests/unit/**",
227         "testing/xpcshell/**",
228         "toolkit/components/**",
229         "toolkit/modules/**",
230       ],
231       rules: {
232         // No declaring variables that are never used
233         "no-unused-vars": [
234           "error",
235           {
236             args: "none",
237             vars: "all",
238           },
239         ],
240       },
241     },
242     {
243       ...browserTestConfig,
244       files: browserTestPaths.map(path => `${path}**`),
245     },
246     {
247       ...removeOverrides(mochitestTestConfig),
248       files: mochitestTestPaths.map(path => `${path}**`),
249       excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
250     },
251     {
252       ...removeOverrides(chromeTestConfig),
253       files: chromeTestPaths.map(path => `${path}**`),
254     },
255     {
256       env: {
257         // Ideally we wouldn't be using the simpletest env here, but our uses of
258         // js files mean we pick up everything from the global scope, which could
259         // be any one of a number of html files. So we just allow the basics...
260         "mozilla/simpletest": true,
261       },
262       files: [
263         ...mochitestTestPaths.map(path => `${path}/**/*.js`),
264         ...chromeTestPaths.map(path => `${path}/**/*.js`),
265       ],
266     },
267     {
268       files: [
269         "netwerk/cookie/test/browser/**",
270         "netwerk/test/browser/**",
271         "netwerk/test/mochitests/**",
272         "netwerk/test/unit*/**",
273       ],
274       rules: {
275         "mozilla/no-arbitrary-setTimeout": "off",
276         "mozilla/no-define-cc-etc": "off",
277         "consistent-return": "off",
278         "no-eval": "off",
279         "no-global-assign": "off",
280         "no-nested-ternary": "off",
281         "no-redeclare": "off",
282         "no-shadow": "off",
283         "no-throw-literal": "off",
284       },
285     },
286     {
287       files: ["layout/**"],
288       rules: {
289         "object-shorthand": "off",
290         "mozilla/avoid-removeChild": "off",
291         "mozilla/consistent-if-bracing": "off",
292         "mozilla/reject-importGlobalProperties": "off",
293         "mozilla/no-arbitrary-setTimeout": "off",
294         "mozilla/no-define-cc-etc": "off",
295         "mozilla/use-chromeutils-generateqi": "off",
296         "mozilla/use-default-preference-values": "off",
297         "mozilla/use-includes-instead-of-indexOf": "off",
298         "mozilla/use-services": "off",
299         "mozilla/use-ownerGlobal": "off",
300         complexity: "off",
301         "consistent-return": "off",
302         "no-array-constructor": "off",
303         "no-caller": "off",
304         "no-cond-assign": "off",
305         "no-extra-boolean-cast": "off",
306         "no-eval": "off",
307         "no-func-assign": "off",
308         "no-global-assign": "off",
309         "no-implied-eval": "off",
310         "no-lonely-if": "off",
311         "no-nested-ternary": "off",
312         "no-new-wrappers": "off",
313         "no-redeclare": "off",
314         "no-restricted-globals": "off",
315         "no-return-await": "off",
316         "no-sequences": "off",
317         "no-throw-literal": "off",
318         "no-useless-concat": "off",
319         "no-undef": "off",
320         "no-unreachable": "off",
321         "no-unsanitized/method": "off",
322         "no-unsanitized/property": "off",
323         "no-unsafe-negation": "off",
324         "no-unused-vars": "off",
325         "no-useless-return": "off",
326       },
327     },
328     {
329       files: [
330         "dom/animation/**",
331         "dom/base/test/*.*",
332         "dom/base/test/unit/test_serializers_entities*.js",
333         "dom/base/test/unit_ipc/**",
334         "dom/base/test/jsmodules/**",
335         "dom/base/*.*",
336         "dom/canvas/**",
337         "dom/encoding/**",
338         "dom/events/**",
339         "dom/fetch/**",
340         "dom/file/**",
341         "dom/html/**",
342         "dom/jsurl/**",
343         "dom/media/tests/**",
344         "dom/media/webaudio/**",
345         "dom/media/webrtc/tests/**",
346         "dom/media/webspeech/**",
347         "dom/messagechannel/**",
348         "dom/midi/**",
349         "dom/network/**",
350         "dom/payments/**",
351         "dom/performance/**",
352         "dom/permission/**",
353         "dom/quota/test/browser/**",
354         "dom/quota/test/common/**",
355         "dom/quota/test/mochitest/**",
356         "dom/quota/test/xpcshell/**",
357         "dom/security/test/cors/**",
358         "dom/security/test/csp/**",
359         "dom/security/test/mixedcontentblocker/**",
360         "dom/serviceworkers/**",
361         "dom/smil/**",
362         "dom/tests/mochitest/**",
363         "dom/u2f/**",
364         "dom/vr/**",
365         "dom/webauthn/**",
366         "dom/webgpu/**",
367         "dom/websocket/**",
368         "dom/workers/**",
369         "dom/worklet/**",
370         "dom/xml/**",
371         "dom/xslt/**",
372         "dom/xul/**",
373         "dom/ipc/test.xhtml",
374       ],
375       rules: {
376         "consistent-return": "off",
377         "mozilla/avoid-removeChild": "off",
378         "mozilla/consistent-if-bracing": "off",
379         "mozilla/no-arbitrary-setTimeout": "off",
380         "mozilla/no-compare-against-boolean-literals": "off",
381         "mozilla/no-define-cc-etc": "off",
382         "mozilla/reject-importGlobalProperties": "off",
383         "mozilla/use-cc-etc": "off",
384         "mozilla/use-chromeutils-generateqi": "off",
385         "mozilla/use-includes-instead-of-indexOf": "off",
386         "mozilla/use-ownerGlobal": "off",
387         "mozilla/use-services": "off",
388         "no-array-constructor": "off",
389         "no-caller": "off",
390         "no-cond-assign": "off",
391         "no-control-regex": "off",
392         "no-debugger": "off",
393         "no-else-return": "off",
394         "no-empty": "off",
395         "no-eval": "off",
396         "no-func-assign": "off",
397         "no-global-assign": "off",
398         "no-implied-eval": "off",
399         "no-lone-blocks": "off",
400         "no-lonely-if": "off",
401         "no-nested-ternary": "off",
402         "no-new-object": "off",
403         "no-new-wrappers": "off",
404         "no-redeclare": "off",
405         "no-return-await": "off",
406         "no-restricted-globals": "off",
407         "no-self-assign": "off",
408         "no-self-compare": "off",
409         "no-sequences": "off",
410         "no-shadow": "off",
411         "no-shadow-restricted-names": "off",
412         "no-sparse-arrays": "off",
413         "no-throw-literal": "off",
414         "no-unreachable": "off",
415         "no-unsanitized/method": "off",
416         "no-unsanitized/property": "off",
417         "no-undef": "off",
418         "no-unused-vars": "off",
419         "no-useless-call": "off",
420         "no-useless-concat": "off",
421         "no-useless-return": "off",
422         "no-with": "off",
423       },
424     },
425     {
426       files: [
427         "testing/mochitest/browser-harness.xhtml",
428         "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
429         "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
430         "testing/mochitest/chrome/test_sanityException.xhtml",
431         "testing/mochitest/chrome/test_sanityException2.xhtml",
432         "testing/mochitest/harness.xhtml",
433       ],
434       rules: {
435         "dot-notation": "off",
436         "object-shorthand": "off",
437         "mozilla/use-services": "off",
438         "mozilla/no-compare-against-boolean-literals": "off",
439         "mozilla/no-useless-parameters": "off",
440         "mozilla/no-useless-removeEventListener": "off",
441         "mozilla/use-cc-etc": "off",
442         "consistent-return": "off",
443         "no-fallthrough": "off",
444         "no-nested-ternary": "off",
445         "no-redeclare": "off",
446         "no-sequences": "off",
447         "no-shadow": "off",
448         "no-throw-literal": "off",
449         "no-undef": "off",
450         "no-unsanitized/property": "off",
451         "no-unused-vars": "off",
452         "no-useless-call": "off",
453       },
454     },
455     {
456       files: [
457         "dom/base/test/chrome/file_bug1139964.xhtml",
458         "dom/base/test/chrome/file_bug549682.xhtml",
459         "dom/base/test/chrome/file_bug616841.xhtml",
460         "dom/base/test/chrome/file_bug990812-1.xhtml",
461         "dom/base/test/chrome/file_bug990812-2.xhtml",
462         "dom/base/test/chrome/file_bug990812-3.xhtml",
463         "dom/base/test/chrome/file_bug990812-4.xhtml",
464         "dom/base/test/chrome/file_bug990812-5.xhtml",
465         "dom/base/test/chrome/file_bug990812.xhtml",
466         "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
467         "dom/base/test/chrome/test_bug339494.xhtml",
468         "dom/base/test/chrome/test_bug429785.xhtml",
469         "dom/base/test/chrome/test_bug467123.xhtml",
470         "dom/base/test/chrome/test_bug683852.xhtml",
471         "dom/base/test/chrome/test_bug780529.xhtml",
472         "dom/base/test/chrome/test_bug800386.xhtml",
473         "dom/base/test/chrome/test_bug884693.xhtml",
474         "dom/base/test/chrome/test_document-element-inserted.xhtml",
475         "dom/base/test/chrome/test_domparsing.xhtml",
476         "dom/base/test/chrome/title_window.xhtml",
477         "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
478         "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
479         "dom/base/test/test_domrequesthelper.xhtml",
480         "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
481         "dom/console/tests/test_jsm.xhtml",
482         "dom/events/test/test_bug1412775.xhtml",
483         "dom/events/test/test_bug336682_2.xhtml",
484         "dom/events/test/test_bug415498.xhtml",
485         "dom/events/test/test_bug602962.xhtml",
486         "dom/events/test/test_bug617528.xhtml",
487         "dom/events/test/test_bug679494.xhtml",
488         "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
489         "dom/indexedDB/test/test_wrappedArray.xhtml",
490         "dom/ipc/test.xhtml",
491         "dom/ipc/tests/test_process_error.xhtml",
492         "dom/notification/test/chrome/test_notification_system_principal.xhtml",
493         "dom/security/test/general/test_bug1277803.xhtml",
494         "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
495         "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
496         "dom/system/tests/test_constants.xhtml",
497         "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
498         "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
499         "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
500         "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
501         "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
502         "dom/tests/mochitest/chrome/window_focus.xhtml",
503         "dom/url/tests/test_bug883784.xhtml",
504         "dom/workers/test/test_WorkerDebugger.xhtml",
505         "dom/workers/test/test_WorkerDebugger_console.xhtml",
506         "dom/workers/test/test_fileReadSlice.xhtml",
507         "dom/workers/test/test_fileReaderSync.xhtml",
508         "dom/workers/test/test_fileSlice.xhtml",
509       ],
510       rules: {
511         "mozilla/no-useless-parameters": "off",
512         "mozilla/no-useless-removeEventListener": "off",
513         "mozilla/use-chromeutils-generateqi": "off",
514         "mozilla/use-services": "off",
515         complexity: "off",
516         "no-array-constructor": "off",
517         "no-caller": "off",
518         "no-empty": "off",
519         "no-eval": "off",
520         "no-lone-blocks": "off",
521         "no-redeclare": "off",
522         "no-shadow": "off",
523         "no-throw-literal": "off",
524         "no-unsanitized/method": "off",
525         "no-useless-return": "off",
526         "object-shorthand": "off",
527       },
528     },
529     {
530       files: [
531         "accessible/**",
532         "devtools/**",
533         "dom/**",
534         "docshell/**",
535         "editor/libeditor/tests/**",
536         "editor/spellchecker/tests/test_bug338427.html",
537         "gfx/**",
538         "image/test/browser/browser_image.js",
539         "js/src/builtin/**",
540         "layout/**",
541         "mobile/android/**",
542         "modules/**",
543         "netwerk/**",
544         "remote/**",
545         "security/manager/**",
546         "services/**",
547         "storage/test/unit/test_vacuum.js",
548         "taskcluster/docker/periodic-updates/scripts/**",
549         "testing/**",
550         "tools/**",
551         "widget/tests/test_assign_event_data.html",
552       ],
553       rules: {
554         "mozilla/prefer-boolean-length-check": "off",
555       },
556     },
557     {
558       // Rules of Hooks broadly checks for camelCase "use" identifiers, so
559       // enable only for paths actually using React to avoid false positives.
560       extends: ["plugin:react-hooks/recommended"],
561       files: [
562         "browser/components/newtab/**",
563         "browser/components/pocket/**",
564         "devtools/**",
565       ],
566     },
567     {
568       // Turn off the osfile rule for osfile.
569       files: ["toolkit/components/osfile/**"],
570       rules: {
571         "mozilla/reject-osfile": "off",
572       },
573     },
574   ],