From 5fb4f28a116bbbb7aaf5439ab6628df91f0ceb7f Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 10 Apr 2023 18:11:03 +0000 Subject: [PATCH] Bug 1425048 - Enable ESLint rules no-unused-vars/no-undef for mobile/android/components/extensions/. r=geckoview-reviewers,extension-reviewers,robwu,owlish Differential Revision: https://phabricator.services.mozilla.com/D174749 --- mobile/android/.eslintrc.js | 23 +++++++++++++------ .../components/extensions/ext-android.js | 11 +++++---- .../extensions/ext-browserAction.js | 3 --- .../components/extensions/ext-pageAction.js | 3 --- .../extensions/test/xpcshell/.eslintrc.js | 6 +++++ 5 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 mobile/android/components/extensions/test/xpcshell/.eslintrc.js diff --git a/mobile/android/.eslintrc.js b/mobile/android/.eslintrc.js index 9668e4feb77e..05a1def15412 100644 --- a/mobile/android/.eslintrc.js +++ b/mobile/android/.eslintrc.js @@ -4,16 +4,25 @@ "use strict"; +const { + globals, +} = require("../../toolkit/components/extensions/parent/.eslintrc.js"); + module.exports = { overrides: [ { - files: [ - // Bug 1425048 - mainly going away, see bug 1583370. - "components/extensions/**", - ], - rules: { - "no-unused-vars": "off", - "no-undef": "off", + files: ["components/extensions/ext-*.js"], + excludedFiles: ["components/extensions/ext-c-*.js"], + globals: { + ...globals, + // These globals are defined in ext-android.js and can only be used in + // the extension files that run in the parent process. + EventDispatcher: true, + ExtensionError: true, + makeGlobalEvent: true, + TabContext: true, + tabTracker: true, + windowTracker: true, }, }, { diff --git a/mobile/android/components/extensions/ext-android.js b/mobile/android/components/extensions/ext-android.js index cac68caae278..d775be02cb43 100644 --- a/mobile/android/components/extensions/ext-android.js +++ b/mobile/android/components/extensions/ext-android.js @@ -3,6 +3,11 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; +/** + * NOTE: If you change the globals in this file, you must check if the globals + * list in mobile/android/.eslintrc.js also needs updating. + */ + ChromeUtils.defineESModuleGetters(this, { GeckoViewTabBridge: "resource://gre/modules/GeckoViewTab.sys.mjs", PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", @@ -29,8 +34,6 @@ var { DefaultWeakMap, ExtensionError } = ExtensionUtils; var { defineLazyGetter } = ExtensionCommon; -global.GlobalEventDispatcher = EventDispatcher.instance; - const BrowserStatusFilter = Components.Constructor( "@mozilla.org/appshell/component/browser-status-filter;1", "nsIWebProgress", @@ -204,9 +207,9 @@ global.makeGlobalEvent = function makeGlobalEvent( }, }; - GlobalEventDispatcher.registerListener(listener2, [event]); + EventDispatcher.instance.registerListener(listener2, [event]); return () => { - GlobalEventDispatcher.unregisterListener(listener2, [event]); + EventDispatcher.instance.unregisterListener(listener2, [event]); }; }, }).api(); diff --git a/mobile/android/components/extensions/ext-browserAction.js b/mobile/android/components/extensions/ext-browserAction.js index a0d9428d055b..26b0715028f1 100644 --- a/mobile/android/components/extensions/ext-browserAction.js +++ b/mobile/android/components/extensions/ext-browserAction.js @@ -6,9 +6,6 @@ "use strict"; -// The ext-* files are imported into the same scopes. -/* import-globals-from ext-android.js */ - XPCOMUtils.defineLazyModuleGetters(this, { GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.jsm", ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.jsm", diff --git a/mobile/android/components/extensions/ext-pageAction.js b/mobile/android/components/extensions/ext-pageAction.js index fceb5e1c0f1a..0c7e41d4e373 100644 --- a/mobile/android/components/extensions/ext-pageAction.js +++ b/mobile/android/components/extensions/ext-pageAction.js @@ -6,9 +6,6 @@ "use strict"; -// The ext-* files are imported into the same scopes. -/* import-globals-from ext-android.js */ - XPCOMUtils.defineLazyModuleGetters(this, { GeckoViewWebExtension: "resource://gre/modules/GeckoViewWebExtension.jsm", ExtensionActionHelper: "resource://gre/modules/GeckoViewWebExtension.jsm", diff --git a/mobile/android/components/extensions/test/xpcshell/.eslintrc.js b/mobile/android/components/extensions/test/xpcshell/.eslintrc.js new file mode 100644 index 000000000000..2e6d214f4b2a --- /dev/null +++ b/mobile/android/components/extensions/test/xpcshell/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + extends: + "../../../../../../toolkit/components/extensions/test/xpcshell/.eslintrc.js", +};