Bug 1758474 - Implement an ESLint rule to disallow passing {} as the target parameter for ChromeUtils.import. r=Gijs,mossop,perftest-reviewers,preferences-reviewers,sparky

Differential Revision: https://phabricator.services.mozilla.com/D140517
This commit is contained in:
Mark Banner 2022-03-11 16:41:29 +00:00
Родитель 020b3254c4
Коммит 8bb4667fae
82 изменённых файлов: 189 добавлений и 218 удалений

Просмотреть файл

@ -885,8 +885,7 @@ var FullScreen = {
XPCOMUtils.defineLazyGetter(FullScreen, "_permissionNotificationIDs", () => {
let { PermissionUI } = ChromeUtils.import(
"resource:///modules/PermissionUI.jsm",
{}
"resource:///modules/PermissionUI.jsm"
);
return (
Object.values(PermissionUI)

Просмотреть файл

@ -1645,8 +1645,7 @@ var gBrowserInit = {
) {
let windowFrameColor = new Color(
...ChromeUtils.import(
"resource:///modules/Windows8WindowFrameColor.jsm",
{}
"resource:///modules/Windows8WindowFrameColor.jsm"
).Windows8WindowFrameColor.get()
);
// Default to black for foreground text.
@ -2339,8 +2338,7 @@ var gBrowserInit = {
try {
DownloadsCommon.initializeAllDataLinks();
ChromeUtils.import(
"resource:///modules/DownloadsTaskbar.jsm",
{}
"resource:///modules/DownloadsTaskbar.jsm"
).DownloadsTaskbar.registerIndicator(window);
if (AppConstants.platform == "macosx") {
ChromeUtils.import(

Просмотреть файл

@ -6,14 +6,12 @@
// Pass an empty scope object to the import to prevent "leaked window property"
// errors in tests.
var Preferences = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm",
{}
).Preferences;
var TelemetryReportingPolicy = ChromeUtils.import(
"resource://gre/modules/TelemetryReportingPolicy.jsm",
{}
).TelemetryReportingPolicy;
var { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
var { TelemetryReportingPolicy } = ChromeUtils.import(
"resource://gre/modules/TelemetryReportingPolicy.jsm"
);
const PREF_BRANCH = "datareporting.policy.";
const PREF_FIRST_RUN = "toolkit.telemetry.reportingpolicy.firstRun";

Просмотреть файл

@ -82,10 +82,8 @@ add_task(async function() {
let updateChannel = null;
try {
updateChannel = ChromeUtils.import(
"resource://gre/modules/UpdateUtils.jsm",
{}
).UpdateUtils.UpdateChannel;
updateChannel = ChromeUtils.import("resource://gre/modules/UpdateUtils.jsm")
.UpdateUtils.UpdateChannel;
} catch (ex) {}
if (!updateChannel) {
Assert.ok(

Просмотреть файл

@ -265,8 +265,7 @@ add_task(async function checkAllTheDTDs() {
add_task(async function checkAllTheFluents() {
let uris = await getAllTheFiles(".ftl");
let { FluentParser, Visitor } = ChromeUtils.import(
"resource://testing-common/FluentSyntax.jsm",
{}
"resource://testing-common/FluentSyntax.jsm"
);
class TextElementVisitor extends Visitor {

Просмотреть файл

@ -407,10 +407,9 @@ add_task(async function checkAllTheCSS() {
// Create a clean iframe to load all the files into. This needs to live at a
// chrome URI so that it's allowed to load and parse any styles.
let testFile = getRootDirectory(gTestPath) + "dummy_page.html";
let HiddenFrame = ChromeUtils.import(
"resource://gre/modules/HiddenFrame.jsm",
{}
).HiddenFrame;
let { HiddenFrame } = ChromeUtils.import(
"resource://gre/modules/HiddenFrame.jsm"
);
let hiddenFrame = new HiddenFrame();
let win = await hiddenFrame.get();
let iframe = win.document.createElementNS(

Просмотреть файл

@ -3,7 +3,7 @@
*/
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
});
ChromeUtils.defineModuleGetter(

Просмотреть файл

@ -3,8 +3,7 @@ const { AddonManagerPrivate } = ChromeUtils.import(
);
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm",
{}
"resource://testing-common/AddonTestUtils.jsm"
);
AddonTestUtils.initMochitest(this);

Просмотреть файл

@ -104,7 +104,7 @@ function promiseIndicatorWindow() {
}
async function assertWebRTCIndicatorStatus(expected) {
let ui = ChromeUtils.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
let ui = ChromeUtils.import("resource:///modules/webrtcUI.jsm").webrtcUI;
let expectedState = expected ? "visible" : "hidden";
let msg = "WebRTC indicator " + expectedState;
if (!expected && ui.showGlobalIndicator) {

Просмотреть файл

@ -1609,8 +1609,7 @@ BrowserGlue.prototype = {
let updateChannel;
try {
updateChannel = ChromeUtils.import(
"resource://gre/modules/UpdateUtils.jsm",
{}
"resource://gre/modules/UpdateUtils.jsm"
).UpdateUtils.UpdateChannel;
} catch (ex) {}
if (updateChannel) {

Просмотреть файл

@ -33,8 +33,7 @@ ChromeUtils.defineModuleGetter(
"resource:///modules/MacAttribution.jsm"
);
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.

Просмотреть файл

@ -9,8 +9,7 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.

Просмотреть файл

@ -19,10 +19,9 @@ function checkSubviewButtonClass(menuId, buttonId, subviewId) {
return async function() {
// Initialize DevTools before starting the test in order to create menuitems in
// menuWebDeveloperPopup.
ChromeUtils.import(
"resource://devtools/shared/loader/Loader.jsm",
{}
).require("devtools/client/framework/devtools-browser");
ChromeUtils.import("resource://devtools/shared/loader/Loader.jsm").require(
"devtools/client/framework/devtools-browser"
);
info(
"Checking for items without the subviewbutton class in " +

Просмотреть файл

@ -318,10 +318,9 @@ DistributionCustomizer.prototype = {
return;
}
let ProfileAge = ChromeUtils.import(
"resource://gre/modules/ProfileAge.jsm",
{}
).ProfileAge;
let { ProfileAge } = ChromeUtils.import(
"resource://gre/modules/ProfileAge.jsm"
);
let profileAge = await ProfileAge();
let resetDate = await profileAge.reset;

Просмотреть файл

@ -21,8 +21,7 @@ const { XPCOMUtils } = ChromeUtils.import(
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
maxLogLevelPref: "browser.esedbreader.loglevel",
prefix: "ESEDBReader",

Просмотреть файл

@ -16,8 +16,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
FxAccountsPairingFlow: "resource://gre/modules/FxAccountsPairing.jsm",
});
const { require } = ChromeUtils.import(
"resource://devtools/shared/loader/Loader.jsm",
{}
"resource://devtools/shared/loader/Loader.jsm"
);
const QR = require("devtools/shared/qrcode/index");

Просмотреть файл

@ -5,7 +5,7 @@
/* import-globals-from preferences.js */
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
});
const FXA_PAGE_LOGGED_OUT = 0;

Просмотреть файл

@ -3,13 +3,9 @@
"use strict";
const { UIState } = ChromeUtils.import(
"resource://services-sync/UIState.jsm",
{}
);
const { UIState } = ChromeUtils.import("resource://services-sync/UIState.jsm");
const { FxAccountsPairingFlow } = ChromeUtils.import(
"resource://gre/modules/FxAccountsPairing.jsm",
{}
"resource://gre/modules/FxAccountsPairing.jsm"
);
// Use sinon for mocking.

Просмотреть файл

@ -41,12 +41,12 @@ function clearHistoryAndWait() {
*/
async function runTest() {
let FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})
.FileUtils;
let DownloadLastDir = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm",
{}
).DownloadLastDir;
let { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
);
let tmpDir = FileUtils.getDir("TmpD", [], true);
let dir1 = newDirectory();

Просмотреть файл

@ -6,12 +6,12 @@
function test() {
waitForExplicitFinish();
let FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})
.FileUtils;
let DownloadLastDir = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm",
{}
).DownloadLastDir;
let { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
);
let MockFilePicker = SpecialPowers.MockFilePicker;
let launcher = {
source: Services.io.newURI("http://test1.com/file"),

Просмотреть файл

@ -6,12 +6,12 @@
function test() {
waitForExplicitFinish();
let FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})
.FileUtils;
let DownloadLastDir = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm",
{}
).DownloadLastDir;
let { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
);
let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);

Просмотреть файл

@ -20,6 +20,11 @@ ChromeUtils.defineModuleGetter(
"TestUtils",
"resource://testing-common/TestUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"FileUtils",
"resource://gre/modules/FileUtils.jsm"
);
function whenNewWindowLoaded(aOptions, aCallback) {
let win = OpenBrowserWindow(aOptions);
@ -56,8 +61,6 @@ async function openAboutPrivateBrowsing() {
}
function newDirectory() {
let FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})
.FileUtils;
let tmpDir = FileUtils.getDir("TmpD", [], true);
let dir = tmpDir.clone();
dir.append("testdir");
@ -66,8 +69,6 @@ function newDirectory() {
}
function newFileInDirectory(aDir) {
let FileUtils = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {})
.FileUtils;
let file = aDir.clone();
file.append("testfile");
file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_FILE);

Просмотреть файл

@ -102,12 +102,10 @@
window.addEventListener("unload", this.destroy);
this.FormHistory = ChromeUtils.import(
"resource://gre/modules/FormHistory.jsm",
{}
"resource://gre/modules/FormHistory.jsm"
).FormHistory;
this.SearchSuggestionController = ChromeUtils.import(
"resource://gre/modules/SearchSuggestionController.jsm",
{}
"resource://gre/modules/SearchSuggestionController.jsm"
).SearchSuggestionController;
Services.obs.addObserver(this.observer, "browser-search-engine-modified");

Просмотреть файл

@ -3,10 +3,9 @@
"use strict";
var Preferences = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm",
{}
).Preferences;
var { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
function test() {
waitForExplicitFinish();

Просмотреть файл

@ -83,10 +83,9 @@ add_task(async function test_add() {
add_task(async function test_diacritics() {
const diacritic_engine = "Foo \u2661";
let Preferences = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm",
{}
).Preferences;
let { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
Preferences.set("browser.search.hiddenOneOffs", diacritic_engine);
await SearchTestUtils.promiseNewSearchEngine(

Просмотреть файл

@ -7,10 +7,9 @@ const searchPopup = document.getElementById("PopupSearchAutoComplete");
const diacritic_engine = "Foo \u2661";
var Preferences = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm",
{}
).Preferences;
var { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
let searchIcon;

Просмотреть файл

@ -28,8 +28,7 @@ add_task(async function init() {
// Make sure that we have a profile before initializing SessionFile
let profd = do_get_profile();
SessionFile = ChromeUtils.import(
"resource:///modules/sessionstore/SessionFile.jsm",
{}
"resource:///modules/sessionstore/SessionFile.jsm"
).SessionFile;
Paths = SessionFile.Paths;

Просмотреть файл

@ -58,8 +58,7 @@ add_task(async function test_migration() {
// Make sure that we have a profile before initializing SessionFile.
let profd = do_get_profile();
SessionFile = ChromeUtils.import(
"resource:///modules/sessionstore/SessionFile.jsm",
{}
"resource:///modules/sessionstore/SessionFile.jsm"
).SessionFile;
Paths = SessionFile.Paths;

Просмотреть файл

@ -4,8 +4,7 @@
function run_test() {
let profd = do_get_profile();
var SessionFile = ChromeUtils.import(
"resource:///modules/sessionstore/SessionFile.jsm",
{}
"resource:///modules/sessionstore/SessionFile.jsm"
).SessionFile;
let sourceSession = do_get_file("data/sessionstore_invalid.js");

Просмотреть файл

@ -9,8 +9,7 @@
function run_test() {
let profd = do_get_profile();
var SessionFile = ChromeUtils.import(
"resource:///modules/sessionstore/SessionFile.jsm",
{}
"resource:///modules/sessionstore/SessionFile.jsm"
).SessionFile;
let sourceSession = do_get_file("data/sessionstore_valid.js");

Просмотреть файл

@ -30,12 +30,11 @@ let { getChromeWindow } = ChromeUtils.import(
const { UIState } = ChromeUtils.import("resource://services-sync/UIState.jsm");
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
});
let log = ChromeUtils.import(
"resource://gre/modules/Log.jsm",
{}
"resource://gre/modules/Log.jsm"
).Log.repository.getLogger("Sync.RemoteTabs");
var EXPORTED_SYMBOLS = ["SyncedTabsDeckComponent"];

Просмотреть файл

@ -5,8 +5,7 @@
"use strict";
let log = ChromeUtils.import(
"resource://gre/modules/Log.jsm",
{}
"resource://gre/modules/Log.jsm"
).Log.repository.getLogger("Sync.RemoteTabs");
var EXPORTED_SYMBOLS = ["SyncedTabsDeckView"];

Просмотреть файл

@ -10,8 +10,7 @@ const { XPCOMUtils } = ChromeUtils.import(
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
let log = ChromeUtils.import(
"resource://gre/modules/Log.jsm",
{}
"resource://gre/modules/Log.jsm"
).Log.repository.getLogger("Sync.RemoteTabs");
XPCOMUtils.defineLazyModuleGetters(this, {

Просмотреть файл

@ -17,8 +17,7 @@ let { getChromeWindow } = ChromeUtils.import(
);
let log = ChromeUtils.import(
"resource://gre/modules/Log.jsm",
{}
"resource://gre/modules/Log.jsm"
).Log.repository.getLogger("Sync.RemoteTabs");
var EXPORTED_SYMBOLS = ["TabListView"];

Просмотреть файл

@ -5,7 +5,7 @@ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
});
do_get_profile(); // fxa needs a profile directory for storage.

Просмотреть файл

@ -107,8 +107,7 @@ class TranslationChild extends JSWindowActorChild {
let engine = Services.prefs.getCharPref("browser.translation.engine");
let importScope = ChromeUtils.import(
`resource:///modules/translation/${engine}Translator.jsm`,
{}
`resource:///modules/translation/${engine}Translator.jsm`
);
let translator = new importScope[engine + "Translator"](
translationDocument,

Просмотреть файл

@ -58,8 +58,7 @@ const TARGET_SEARCHENGINE_PREFIX = "searchEngine-";
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
maxLogLevelPref: PREF_LOG_LEVEL,
prefix: "UITour",

Просмотреть файл

@ -91,7 +91,7 @@ class ProvidersManager {
// providers at the front.
this.providers = [];
for (let [symbol, module] of Object.entries(localProviderModules)) {
let { [symbol]: provider } = ChromeUtils.import(module, {});
let { [symbol]: provider } = ChromeUtils.import(module);
this.registerProvider(provider);
}
// Tracks ongoing Query instances by queryContext.
@ -105,7 +105,7 @@ class ProvidersManager {
// This maps muxer names to muxers.
this.muxers = new Map();
for (let [symbol, module] of Object.entries(localMuxerModules)) {
let { [symbol]: muxer } = ChromeUtils.import(module, {});
let { [symbol]: muxer } = ChromeUtils.import(module);
this.registerMuxer(muxer);
}
}

Просмотреть файл

@ -278,8 +278,7 @@
this.setAttribute("formautofillattached", "true");
let { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm",
{}
"resource://gre/modules/AppConstants.jsm"
);
let buttonTextBundleKey;

Просмотреть файл

@ -6,8 +6,7 @@
"use strict";
const { setTimeout, clearTimeout } = ChromeUtils.import(
"resource://gre/modules/Timer.jsm",
{}
"resource://gre/modules/Timer.jsm"
);
var FormAutofillHandler, OSKeyStore;

Просмотреть файл

@ -4,8 +4,6 @@
*/
"use strict";
ChromeUtils.import("resource:///modules/CustomizableUI.jsm", {});
add_task(async function testScreenshotButtonDisabled() {
info("Test the Screenshots button in the panel");

Просмотреть файл

@ -1,7 +1,7 @@
/* globals ProcessHangMonitor */
const { WebExtensionPolicy } = Cu.getGlobalForObject(
ChromeUtils.import("resource://gre/modules/Services.jsm", {})
ChromeUtils.import("resource://gre/modules/Services.jsm")
);
const { UpdateUtils } = ChromeUtils.import(

Просмотреть файл

@ -120,10 +120,9 @@ add_task(async function test_sessionRestore() {
};
// Save the current session.
let SessionStore = ChromeUtils.import(
"resource:///modules/sessionstore/SessionStore.jsm",
{}
).SessionStore;
let { SessionStore } = ChromeUtils.import(
"resource:///modules/sessionstore/SessionStore.jsm"
);
// Load the custom state and wait for SSTabRestored, as we want to make sure
// that the URI counting code was hit.

Просмотреть файл

@ -36,10 +36,8 @@ async function setup() {
let aAddon = await AddonManager.getAddonByID("mozscreenshots@mozilla.org");
isnot(aAddon, null, "The mozscreenshots extension should be installed");
TestRunner = ChromeUtils.import(
"resource://mozscreenshots/TestRunner.jsm",
{}
).TestRunner;
TestRunner = ChromeUtils.import("resource://mozscreenshots/TestRunner.jsm")
.TestRunner;
TestRunner.initTest(this);
}

Просмотреть файл

@ -17,8 +17,7 @@ const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
// See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
const PREF_LOG_LEVEL = "extensions.mozscreenshots@mozilla.org.loglevel";
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
maxLogLevel: "info",
maxLogLevelPref: PREF_LOG_LEVEL,

Просмотреть файл

@ -10,10 +10,9 @@ registerManifests(manifests);
function run_test() {
const uuidGenerator = Services.uuid;
let newAppInfo = ChromeUtils.import(
"resource://testing-common/AppInfo.jsm",
{}
).newAppInfo;
let { newAppInfo } = ChromeUtils.import(
"resource://testing-common/AppInfo.jsm"
);
let XULAppInfo = newAppInfo({
name: "XPCShell",
ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",

Просмотреть файл

@ -8,8 +8,7 @@ const Services = require("Services");
const ChromeUtils = require("ChromeUtils");
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js",
{}
"resource://services-settings/remote-settings.js"
);
const TARGET_BROWSER_ID = [

Просмотреть файл

@ -5,7 +5,7 @@ reject-chromeutils-import-params
largely deprecated.
The use of object destructuring is preferred over the second parameter being
``this``.
``this`` or ``{}``.
Using explicit exports is preferred over the second parameter being ``null``.
@ -16,6 +16,7 @@ Examples of incorrect code for this rule:
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
ChromeUtils.import("resource://gre/modules/Services.jsm", null);
ChromeUtils.import("resource://gre/modules/Services.jsm", {});
Examples of correct code for this rule:
---------------------------------------

Просмотреть файл

@ -37,8 +37,7 @@ ChromeUtils.defineModuleGetter(
XPCOMUtils.defineLazyGetter(this, "Log", () => {
return ChromeUtils.import(
"resource://gre/modules/AndroidLog.jsm",
{}
"resource://gre/modules/AndroidLog.jsm"
).AndroidLog.bind("Push");
});

Просмотреть файл

@ -1,8 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
var Downloads = ChromeUtils.import("resource://gre/modules/Downloads.jsm", {})
.Downloads;
var { Downloads } = ChromeUtils.import("resource://gre/modules/Downloads.jsm");
var gTestRoot = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content/",

Просмотреть файл

@ -6,7 +6,7 @@ const ConsoleAPIStorage = Cc["@mozilla.org/consoleAPI-storage;1"].getService(
);
const { WebExtensionPolicy } = Cu.getGlobalForObject(
ChromeUtils.import("resource://gre/modules/Services.jsm", {})
ChromeUtils.import("resource://gre/modules/Services.jsm")
);
const FAKE_ADDON_ID = "test-webext-addon@mozilla.org";

Просмотреть файл

@ -39,10 +39,9 @@ add_task(async function test_windowlessBrowserTroubleshootCrash() {
}
ok(true, "not crashed");
var Troubleshoot = ChromeUtils.import(
"resource://gre/modules/Troubleshoot.jsm",
{}
).Troubleshoot;
var { Troubleshoot } = ChromeUtils.import(
"resource://gre/modules/Troubleshoot.jsm"
);
var data = await new Promise((resolve, reject) => {
Troubleshoot.snapshot(data => {
resolve(data);

Просмотреть файл

@ -88,7 +88,7 @@ var GeckoViewUtils = {
XPCOMUtils.defineLazyGetter(scope, name, _ => {
let ret = undefined;
if (module) {
ret = ChromeUtils.import(module, {})[name];
ret = ChromeUtils.import(module)[name];
} else if (service) {
ret = Cc[service].getService(Ci.nsISupports).wrappedJSObject;
} else if (typeof handler === "function") {

Просмотреть файл

@ -9,7 +9,7 @@ function test() {
// We overload this test to include verifying that httpd.js is
// importable as a testing-only JS module.
ChromeUtils.import("resource://testing-common/httpd.js", {});
ChromeUtils.import("resource://testing-common/httpd.js");
nextTest();
}

Просмотреть файл

@ -12,10 +12,6 @@
// * it does a sanity check to ensure other cert verifier behavior is
// unmodified
const { setTimeout } = ChromeUtils.import(
"resource://gre/modules/Timer.jsm",
{}
);
const { RemoteSecuritySettings } = ChromeUtils.import(
"resource://gre/modules/psm/RemoteSecuritySettings.jsm"
);

Просмотреть файл

@ -18,7 +18,7 @@ function expectImportsToSucceed(mm, base = MODULE_BASE) {
let resource = base + m;
let succeeded = false;
try {
ChromeUtils.import(resource, {});
ChromeUtils.import(resource);
succeeded = true;
} catch (e) {}
@ -33,7 +33,7 @@ function expectImportsToFail(mm, base = MODULE_BASE) {
let resource = base + m;
let succeeded = false;
try {
ChromeUtils.import(resource, {});
ChromeUtils.import(resource);
succeeded = true;
} catch (e) {}

Просмотреть файл

@ -7,6 +7,6 @@ function run_test() {
for (let m of modules) {
let resource = "resource://services-crypto/" + m;
_("Attempting to import: " + resource);
ChromeUtils.import(resource, {});
ChromeUtils.import(resource);
}
}

Просмотреть файл

@ -85,8 +85,7 @@ FxAccountsPushService.prototype = {
this.fxai = options.fxai;
} else {
let { fxAccounts } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
{}
"resource://gre/modules/FxAccounts.jsm"
);
this.fxai = fxAccounts._internal;
}

Просмотреть файл

@ -4,20 +4,16 @@
"use strict";
const { FxAccountsPairingFlow } = ChromeUtils.import(
"resource://gre/modules/FxAccountsPairing.jsm",
{}
"resource://gre/modules/FxAccountsPairing.jsm"
);
const { EventEmitter } = ChromeUtils.import(
"resource://gre/modules/EventEmitter.jsm",
{}
"resource://gre/modules/EventEmitter.jsm"
);
const { PromiseUtils } = ChromeUtils.import(
"resource://gre/modules/PromiseUtils.jsm",
{}
"resource://gre/modules/PromiseUtils.jsm"
);
const { CryptoUtils } = ChromeUtils.import(
"resource://services-crypto/utils.js",
{}
"resource://services-crypto/utils.js"
);
XPCOMUtils.defineLazyModuleGetters(this, {
jwcrypto: "resource://services-crypto/jwcrypto.jsm",

Просмотреть файл

@ -36,8 +36,7 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
// See LOG_LEVELS in Console.jsm. Common examples: "all", "debug", "info", "warn", "error".
XPCOMUtils.defineLazyGetter(this, "log", () => {
const { ConsoleAPI } = ChromeUtils.import(
"resource://gre/modules/Console.jsm",
{}
"resource://gre/modules/Console.jsm"
);
return new ConsoleAPI({
maxLogLevel: "warn",

Просмотреть файл

@ -20,7 +20,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function() {
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js", {});
return ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
});
this.EXPORTED_SYMBOLS = ["SyncDisconnectInternal", "SyncDisconnect"];
@ -32,7 +32,7 @@ this.SyncDisconnectInternal = {
// mocked by tests.
getWeave() {
return ChromeUtils.import("resource://services-sync/main.js", {}).Weave;
return ChromeUtils.import("resource://services-sync/main.js").Weave;
},
// Returns a promise that resolves when we are not syncing, waiting until

Просмотреть файл

@ -39,12 +39,12 @@ function run_test() {
for (let m of modules) {
let res = "resource://services-sync/" + m;
_("Attempting to load " + res);
ChromeUtils.import(res, {});
ChromeUtils.import(res);
}
for (let m of testingModules) {
let res = "resource://testing-common/services/sync/" + m;
_("Attempting to load " + res);
ChromeUtils.import(res, {});
ChromeUtils.import(res);
}
}

Просмотреть файл

@ -272,10 +272,9 @@ TalosPowersService.prototype = {
// We can wait for various startup items here to complete during
// the getInfo.html step for Talos so that subsequent runs don't
// have to do things like re-request the SafeBrowsing list.
let SafeBrowsing = ChromeUtils.import(
"resource://gre/modules/SafeBrowsing.jsm",
{}
).SafeBrowsing;
let { SafeBrowsing } = ChromeUtils.import(
"resource://gre/modules/SafeBrowsing.jsm"
);
// Speed things up in case nobody else called this:
SafeBrowsing.init();

Просмотреть файл

@ -562,8 +562,7 @@ function _execute_test() {
let coverageCollector = null;
if (typeof _JSCOV_DIR === "string") {
let _CoverageCollector = ChromeUtils.import(
"resource://testing-common/CoverageUtils.jsm",
{}
"resource://testing-common/CoverageUtils.jsm"
).CoverageCollector;
coverageCollector = new _CoverageCollector(_JSCOV_DIR);
}

Просмотреть файл

@ -15,8 +15,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.

Просмотреть файл

@ -11,8 +11,7 @@ const { XPCOMUtils } = ChromeUtils.import(
);
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.

Просмотреть файл

@ -150,10 +150,9 @@ var FormAutofill = {
scope.debug = debug;
XPCOMUtils.defineLazyGetter(scope, "log", () => {
let ConsoleAPI = ChromeUtils.import(
"resource://gre/modules/Console.jsm",
{}
).ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import(
"resource://gre/modules/Console.jsm"
);
return new ConsoleAPI({
maxLogLevelPref: "extensions.formautofill.loglevel",
prefix: logPrefix,

Просмотреть файл

@ -38,7 +38,7 @@ if (typeof Components != "undefined") {
this.exports = {};
({ Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"));
this.Services = Services;
Meta = ChromeUtils.import("resource://gre/modules/PromiseWorker.jsm", {})
Meta = ChromeUtils.import("resource://gre/modules/PromiseWorker.jsm")
.BasePromiseWorker.Meta;
} else {
importScripts("resource://gre/modules/workers/require.js");

Просмотреть файл

@ -7,8 +7,7 @@ const { LoginRelatedRealmsParent } = ChromeUtils.import(
"resource://gre/modules/LoginRelatedRealms.jsm"
);
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js",
{}
"resource://services-settings/remote-settings.js"
);
const REMOTE_SETTINGS_COLLECTION = "websites-with-shared-credential-backends";

Просмотреть файл

@ -9,8 +9,7 @@
"use strict";
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js",
{}
"resource://services-settings/remote-settings.js"
);
const REMOTE_SETTINGS_COLLECTION = "password-recipes";

Просмотреть файл

@ -27,8 +27,7 @@ XPCOMUtils.defineLazyServiceGetters(this, {
XPCOMUtils.defineLazyGlobalGetters(this, ["XMLSerializer"]);
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
let consoleOptions = {
// tip: set maxLogLevel to "debug" and use log.debug() to create detailed
// messages during development. See LOG_LEVELS in Console.jsm for details.

Просмотреть файл

@ -482,7 +482,7 @@
if (this.isRemoteBrowser) {
if (!this._remoteFinder) {
let jsm = "resource://gre/modules/FinderParent.jsm";
let { FinderParent } = ChromeUtils.import(jsm, {});
let { FinderParent } = ChromeUtils.import(jsm);
this._remoteFinder = new FinderParent(this);
}
return this._remoteFinder;
@ -492,8 +492,9 @@
return null;
}
let Finder = ChromeUtils.import("resource://gre/modules/Finder.jsm", {})
.Finder;
let { Finder } = ChromeUtils.import(
"resource://gre/modules/Finder.jsm"
);
this._finder = new Finder(this.docShell);
}
return this._finder;

Просмотреть файл

@ -50,8 +50,9 @@
return null;
}
let Finder = ChromeUtils.import("resource://gre/modules/Finder.jsm", {})
.Finder;
let { Finder } = ChromeUtils.import(
"resource://gre/modules/Finder.jsm"
);
this._finder = new Finder(this.docShell);
}
return this._finder;

Просмотреть файл

@ -377,8 +377,7 @@ var OSKeyStore = {
};
XPCOMUtils.defineLazyGetter(this, "log", () => {
let ConsoleAPI = ChromeUtils.import("resource://gre/modules/Console.jsm", {})
.ConsoleAPI;
let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm");
return new ConsoleAPI({
maxLogLevelPref: "toolkit.osKeyStore.loglevel",
prefix: "OSKeyStore",

Просмотреть файл

@ -229,8 +229,7 @@ var dataProviders = {
if (AppConstants.MOZ_UPDATER) {
data.updateChannel = ChromeUtils.import(
"resource://gre/modules/UpdateUtils.jsm",
{}
"resource://gre/modules/UpdateUtils.jsm"
).UpdateUtils.UpdateChannel;
}

Просмотреть файл

@ -720,7 +720,7 @@ var AddonManagerInternal = {
CATEGORY_PROVIDER_MODULE
)) {
try {
ChromeUtils.import(url, {});
ChromeUtils.import(url);
logger.debug(`Loaded provider scope for ${url}`);
} catch (e) {
AddonManagerPrivate.recordException(

Просмотреть файл

@ -54,7 +54,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
});
XPCOMUtils.defineLazyGetter(this, "IconDetails", () => {
return ChromeUtils.import("resource://gre/modules/ExtensionParent.jsm", {})
return ChromeUtils.import("resource://gre/modules/ExtensionParent.jsm")
.ExtensionParent.IconDetails;
});

Просмотреть файл

@ -1,13 +1,11 @@
/* eslint max-len: ["error", 80] */
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm",
{}
"resource://testing-common/AddonTestUtils.jsm"
);
const { ExtensionPermissions } = ChromeUtils.import(
"resource://gre/modules/ExtensionPermissions.jsm",
{}
"resource://gre/modules/ExtensionPermissions.jsm"
);
const SUPPORT_URL = Services.urlFormatter.formatURL(

Просмотреть файл

@ -1,6 +1,5 @@
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm",
{}
"resource://testing-common/AddonTestUtils.jsm"
);
AddonTestUtils.initMochitest(this);

Просмотреть файл

@ -11,8 +11,7 @@ registerCleanupFunction(() => {
});
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm",
{}
"resource://testing-common/AddonTestUtils.jsm"
);
const PREF_UPDATE_ENABLED = "extensions.update.enabled";

Просмотреть файл

@ -19,6 +19,13 @@ function isIdentifier(node, id) {
}
module.exports = function(context) {
function getRangeAfterArgToEnd(argNumber, args) {
let sourceCode = context.getSourceCode();
return [
sourceCode.getTokenAfter(args[argNumber]).range[0],
args[args.length - 1].range[1],
];
}
// ---------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------
@ -31,16 +38,14 @@ module.exports = function(context) {
isIdentifier(callee.property, "import") &&
node.arguments.length >= 2
) {
if (
node.arguments[1].type == "Literal" &&
node.arguments[1].raw == "null"
) {
let targetObj = node.arguments[1];
if (targetObj.type == "Literal" && targetObj.raw == "null") {
context.report(
node,
"ChromeUtils.import should not be called with (..., null) to " +
"retrieve the JSM global object. Rely on explicit exports instead."
);
} else if (node.arguments[1].type == "ThisExpression") {
} else if (targetObj.type == "ThisExpression") {
context.report({
node,
message:
@ -63,6 +68,27 @@ module.exports = function(context) {
},
],
});
} else if (
targetObj.type == "ObjectExpression" &&
targetObj.properties.length == 0
) {
context.report({
node,
message:
"Passing an empty object to ChromeUtils.import is unnecessary",
suggest: [
{
desc:
"Passing an empty object to ChromeUtils.import is " +
"unnecessary - remove the empty object",
fix: fixer => {
return fixer.removeRange(
getRangeAfterArgToEnd(0, node.arguments)
);
},
},
],
});
}
}
},

Просмотреть файл

@ -82,5 +82,19 @@ const { My } = ChromeUtils.import("resource://some/path/to/My.jsm");`,
},
],
},
{
code: 'ChromeUtils.import("resource://some/path/to/My.js", {})',
errors: [
{
suggestions: [
{
desc:
"Passing an empty object to ChromeUtils.import is unnecessary - remove the empty object",
output: `ChromeUtils.import("resource://some/path/to/My.js")`,
},
],
},
],
},
],
});