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