Bug 1781957 - Remove argument to nsCSSFrameConstructor::AddFCItemsForAnonymousContent...
[gecko.git] / .eslintrc.js
blobd101ff559e523007ffbd6fbd9dffe3e2d7dcfd39
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/**/",
33   // Special case for xpcshell harness.
34   "testing/xpcshell/example/unit/",
37 const browserTestPaths = ["**/test*/**/browser*/"];
39 const mochitestTestPaths = [
40   // Note: we do not want to match testing/mochitest as that would apply
41   // too many globals for that directory.
42   "**/test/mochitest/",
43   "**/tests/mochitest/",
44   "**/test/mochitests/",
45   "testing/mochitest/tests/SimpleTest/",
46   "testing/mochitest/tests/Harness_sanity/",
49 const chromeTestPaths = ["**/test*/chrome/"];
51 const ignorePatterns = [
52   ...fs
53     .readFileSync(
54       path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
55     )
56     .toString("utf-8")
57     .split("\n"),
58   ...fs
59     .readFileSync(
60       path.join(
61         __dirname,
62         "devtools",
63         "client",
64         "debugger",
65         "src",
66         ".eslintignore"
67       )
68     )
69     .toString("utf-8")
70     .split("\n")
71     .filter(p => p && !p.startsWith("#"))
72     .map(p => `devtools/client/debugger/src/${p}`),
75 module.exports = {
76   parser: "@babel/eslint-parser",
77   parserOptions: {
78     sourceType: "script",
79     babelOptions: {
80       configFile: path.join(__dirname, ".babel-eslint.rc.js"),
81     },
82   },
83   settings: {
84     "import/extensions": [".mjs"],
85   },
86   ignorePatterns,
87   // Ignore eslint configurations in parent directories.
88   root: true,
89   // New rules and configurations should generally be added in
90   // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
91   // allow external repositories that use the plugin to pick them up as well.
92   extends: ["plugin:mozilla/recommended"],
93   plugins: ["mozilla", "import"],
94   overrides: [
95     {
96       // All .eslintrc.js files are in the node environment, so turn that
97       // on here.
98       // https://github.com/eslint/eslint/issues/13008
99       files: [".eslintrc.js"],
100       env: {
101         node: true,
102         browser: false,
103       },
104     },
105     {
106       files: ["*.mjs"],
107       rules: {
108         "import/default": "error",
109         "import/export": "error",
110         "import/named": "error",
111         "import/namespace": "error",
112         "import/newline-after-import": "error",
113         "import/no-anonymous-default-export": "error",
114         "import/no-duplicates": "error",
115         "import/no-absolute-path": "error",
116         "import/no-named-default": "error",
117         "import/no-named-as-default": "error",
118         "import/no-named-as-default-member": "error",
119         "import/no-self-import": "error",
120         "import/no-unassigned-import": "error",
121         "import/no-unresolved": "error",
122         "import/no-useless-path-segments": "error",
123       },
124     },
125     {
126       files: [
127         // Bug 1773473 - Turn off no-unresolved for system mjs modules, as we
128         // do not yet have a resolver for resource:// uris.
129         "*.sys.mjs",
130         // Bug 1773475 - For now, turn off no-unresolved on some paths where we import
131         // from node_modules, as the ESLint setup only installs modules at the
132         // top-level.
133         "devtools/shared/compatibility/**",
134       ],
135       rules: {
136         "import/no-unresolved": "off",
137       },
138     },
139     {
140       files: [
141         "*.html",
142         "*.xhtml",
143         "*.xml",
144         "js/src/builtin/**/*.js",
145         "js/src/shell/**/*.js",
146       ],
147       rules: {
148         // Curly brackets are required for all the tree via recommended.js,
149         // however these files aren't auto-fixable at the moment.
150         curly: "off",
151       },
152     },
153     {
154       // TODO: Bug 1515949. Enable no-undef for gfx/
155       files: "gfx/layers/apz/test/mochitest/**",
156       rules: {
157         "no-undef": "off",
158       },
159     },
160     {
161       ...removeOverrides(xpcshellTestConfig),
162       files: xpcshellTestPaths.map(path => `${path}**`),
163       excludedFiles: "devtools/**",
164     },
165     {
166       // If it is an xpcshell head file, we turn off global unused variable checks, as it
167       // would require searching the other test files to know if they are used or not.
168       // This would be expensive and slow, and it isn't worth it for head files.
169       // We could get developers to declare as exported, but that doesn't seem worth it.
170       files: xpcshellTestPaths.map(path => `${path}head*.js`),
171       rules: {
172         "no-unused-vars": [
173           "error",
174           {
175             args: "none",
176             vars: "local",
177           },
178         ],
179       },
180     },
181     {
182       // This section enables warning of no-unused-vars globally for all test*.js
183       // files in xpcshell test paths.
184       // These are turned into errors with selected exclusions in the next
185       // section.
186       // Bug 1612907: This section should go away once the exclusions are removed
187       // from the following section.
188       files: xpcshellTestPaths.map(path => `${path}test*.js`),
189       rules: {
190         // No declaring variables that are never used
191         "no-unused-vars": [
192           "warn",
193           {
194             args: "none",
195             vars: "all",
196           },
197         ],
198       },
199     },
200     {
201       // This section makes global issues with no-unused-vars be reported as
202       // errors - except for the excluded lists which are being fixed in the
203       // dependencies of bug 1612907.
204       files: xpcshellTestPaths.map(path => `${path}test*.js`),
205       excludedFiles: [
206         // These are suitable as good first bugs, take one or two related lines
207         // per bug.
208         "extensions/permissions/**",
209         "image/test/unit/**",
210         "intl/uconv/tests/unit/test_bug340714.js",
211         "modules/libjar/test/unit/test_empty_jar_telemetry.js",
212         "modules/libjar/zipwriter/test/unit/test_alignment.js",
213         "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
214         "modules/libjar/zipwriter/test/unit/test_storedata.js",
215         "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
216         "modules/libpref/test/unit/test_dirtyPrefs.js",
217         "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
218         "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
220         // These are more complicated bugs which may require some in-depth
221         // investigation or different solutions. They are also likely to be
222         // a reasonable size.
223         "browser/components/**",
224         "browser/modules/**",
225         "dom/**",
226         "netwerk/**",
227         "security/manager/ssl/tests/unit/**",
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   ],