Commit 05e3f1ea authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1646183 - Extend ESLint rule reject-importGlobalProperties to also handle...

Bug 1646183 - Extend ESLint rule reject-importGlobalProperties to also handle defineLazyGlobalGetters. r=arai,webdriver-reviewers,webcompat-reviewers,extension-reviewers,whimboo,twisniewski,kmag

Differential Revision: https://phabricator.services.mozilla.com/D150353
parent efb5f18b
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ var { PlacesTestUtils } = ChromeUtils.import(
  "resource://testing-common/PlacesTestUtils.jsm"
);

XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);

ChromeUtils.defineModuleGetter(
  this,
  "FileUtils",
+0 −2
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ ChromeUtils.defineModuleGetter(
  "resource://gre/modules/PromiseWorker.jsm"
);

XPCOMUtils.defineLazyGlobalGetters(this, ["DOMParser"]);

const CACHE_WORKER_URL = "resource://activity-stream/lib/cache-worker.js";
const NEWTAB_RENDER_URL =
  "resource://activity-stream/data/content/newtab-render.js";
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ const { WebRequest } = ChromeUtils.import(
  "resource://gre/modules/WebRequest.jsm"
);

// eslint-disable-next-line mozilla/reject-importGlobalProperties
XPCOMUtils.defineLazyGlobalGetters(this, ["ChannelWrapper"]);

XPCOMUtils.defineLazyGetter(this, "searchInitialized", () => {
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

/* global ExtensionAPI, ExtensionCommon, ExtensionParent, Services, XPCOMUtils */

// eslint-disable-next-line mozilla/reject-importGlobalProperties
XPCOMUtils.defineLazyGlobalGetters(this, ["URL", "ChannelWrapper"]);

class AllowList {
+41 −3
Original line number Diff line number Diff line
reject-importGlobalProperties
=============================

Rejects calls to ``Cu.importGlobalProperties``. This is defined in the
recommended configuration to allow non-WebIDL imports, but reject others.
Rejects calls to ``Cu.importGlobalProperties`` or
``XPCOMUtils.defineLazyGlobalGetters``.

In some places in the tree, it will reject everything.
In system modules all the required properties should already be available. In
non-module code or non-system modules, webidl defined interfaces should already
be available and hence do not need importing.

Options
-------

* "everything": Disallows using the import/getters completely.
* "allownonwebidl": Disallows using the import functions for webidl symbols. Allows
  other symbols.

everything
----------

Incorrect code for this option:

.. code-block:: js

    Cu.importGlobalProperties(['TextEncoder']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['TextEncoder']);

allownonwebidl
--------------

Incorrect code for this option:

.. code-block:: js

    // AnimationEffect is a webidl property.
    Cu.importGlobalProperties(['AnimationEffect']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['AnimationEffect']);

Correct code for this option:

.. code-block:: js

    // TextEncoder is not defined by webidl.
    Cu.importGlobalProperties(['TextEncoder']);
    XPCOMUtils.defineLazyGlobalGetters(this, ['TextEncoder']);
Loading