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