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