Skip to content

Commit

Permalink
Bug 1758474 - Implement an ESLint rule to disallow passing {} as the …
Browse files Browse the repository at this point in the history
…target parameter for ChromeUtils.import. r=Gijs,mossop,perftest-reviewers,preferences-reviewers,sparky

Differential Revision: https://phabricator.services.mozilla.com/D140517
  • Loading branch information
Standard8 committed Mar 11, 2022
1 parent 475be46 commit dd5cb64
Show file tree
Hide file tree
Showing 82 changed files with 189 additions and 218 deletions.
3 changes: 1 addition & 2 deletions browser/base/content/browser-fullScreenAndPointerLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions browser/base/content/test/static/browser_parsable_css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/sync/browser_fxa_web_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/webrtc/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions browser/components/BrowserGlue.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions browser/components/attribution/AttributionCode.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions browser/components/attribution/MacAttribution.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down
7 changes: 3 additions & 4 deletions browser/components/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions browser/components/migration/ESEDBReader.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions browser/components/preferences/fxaPairDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion browser/components/preferences/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions browser/components/preferences/tests/browser_sync_pairing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions browser/components/privatebrowsing/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions browser/components/search/content/searchbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading

0 comments on commit dd5cb64

Please sign in to comment.