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