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