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