diff --git a/.eslintrc.js b/.eslintrc.js index c4c3a8ec9882..a802ecfe5082 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -310,7 +310,6 @@ module.exports = { rules: { "mozilla/lazy-getter-object-name": "error", "mozilla/reject-eager-module-in-lazy-getter": "error", - "mozilla/reject-global-this": "error", "mozilla/reject-globalThis-modification": "error", // For all system modules, we expect no properties to need importing, // hence reject everything. diff --git a/docs/code-quality/lint/linters/eslint-plugin-mozilla/rules/reject-global-this.rst b/docs/code-quality/lint/linters/eslint-plugin-mozilla/rules/reject-global-this.rst deleted file mode 100644 index b3d94321f5b7..000000000000 --- a/docs/code-quality/lint/linters/eslint-plugin-mozilla/rules/reject-global-this.rst +++ /dev/null @@ -1,29 +0,0 @@ -reject-global-this -====================== - -Rejects global ``this`` usage in JSM files. The global ``this`` is not -available in ESM, and this is a preparation for the migration. - -Examples of incorrect code for this rule: ------------------------------------------ - -.. code-block:: js - - this.EXPORTED_SYMBOLS = ["foo"]; - - XPCOMUtils.defineLazyModuleGetters(this, { - AddonManager: "resource://gre/modules/AddonManager.jsm", - }); - - -Examples of correct code for this rule: ---------------------------------------- - -.. code-block:: js - - const EXPORTED_SYMBOLS = ["foo"]; - - const lazy = {}; - XPCOMUtils.defineLazyModuleGetters(lazy, { - AddonManager: "resource://gre/modules/AddonManager.jsm", - }); diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js index 72057126bc35..24013f897081 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js @@ -250,7 +250,6 @@ const extraRules = [ rules: { "mozilla/lazy-getter-object-name": "error", "mozilla/reject-eager-module-in-lazy-getter": "error", - "mozilla/reject-global-this": "error", "mozilla/reject-globalThis-modification": "error", // For all system modules, we expect no properties to need importing, // hence reject everything. diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js index 1ffb9a6e916e..c59428b4c8e6 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.js @@ -62,7 +62,6 @@ const plugin = { "prefer-formatValues": require("./rules/prefer-formatValues"), "reject-addtask-only": require("./rules/reject-addtask-only"), "reject-eager-module-in-lazy-getter": require("./rules/reject-eager-module-in-lazy-getter"), - "reject-global-this": require("./rules/reject-global-this"), "reject-globalThis-modification": require("./rules/reject-globalThis-modification"), "reject-import-system-module-from-non-system": require("./rules/reject-import-system-module-from-non-system"), "reject-importGlobalProperties": require("./rules/reject-importGlobalProperties"), diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-global-this.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-global-this.js deleted file mode 100644 index 1067a4befac5..000000000000 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-global-this.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @fileoverview Reject attempts to use the global object in jsms. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -"use strict"; - -const helpers = require("../helpers"); - -// ----------------------------------------------------------------------------- -// Rule Definition -// ----------------------------------------------------------------------------- - -module.exports = { - meta: { - docs: { - url: "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/rules/reject-global-this.html", - }, - messages: { - avoidGlobalThis: "JSM should not use the global this", - }, - schema: [], - type: "problem", - }, - - create(context) { - return { - ThisExpression(node) { - if (!helpers.getIsGlobalThis(helpers.getAncestors(context, node))) { - return; - } - - context.report({ - node, - messageId: "avoidGlobalThis", - }); - }, - }; - }, -}; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/tests/reject-global-this.js b/tools/lint/eslint/eslint-plugin-mozilla/tests/reject-global-this.js deleted file mode 100644 index ec9ba711dc0b..000000000000 --- a/tools/lint/eslint/eslint-plugin-mozilla/tests/reject-global-this.js +++ /dev/null @@ -1,51 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -// ------------------------------------------------------------------------------ -// Requirements -// ------------------------------------------------------------------------------ - -var rule = require("../lib/rules/reject-global-this"); -var RuleTester = require("eslint").RuleTester; - -// class static block is available from ES2022 = 13. -const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "latest" } }); - -// ------------------------------------------------------------------------------ -// Tests -// ------------------------------------------------------------------------------ - -function invalidCode(code) { - return { - code, - errors: [{ messageId: "avoidGlobalThis", type: "ThisExpression" }], - }; -} - -ruleTester.run("reject-top-level-await", rule, { - valid: [ - "function f() { this; }", - "(function f() { this; });", - "({ foo() { this; } });", - "({ get foo() { this; } })", - "({ set foo(x) { this; } })", - "class X { foo() { this; } }", - "class X { get foo() { this; } }", - "class X { set foo(x) { this; } }", - "class X { static foo() { this; } }", - "class X { static get foo() { this; } }", - "class X { static set foo(x) { this; } }", - "class X { P = this; }", - "class X { #P = this; }", - "class X { static { this; } }", - ], - invalid: [ - invalidCode("this;"), - invalidCode("() => this;"), - - invalidCode("this.foo = 10;"), - invalidCode("ChromeUtils.defineModuleGetter(this, {});"), - ], -});