Bug 1936051 - Part 5: Remove the reject-global-this rule. r=Standard8,frontend-codestyle-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D233731
This commit is contained in:
Tooru Fujisawa
2025-01-23 12:09:33 +00:00
parent 7ea13bcadf
commit 2b05a3b05e
6 changed files with 0 additions and 126 deletions

View File

@@ -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.

View File

@@ -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",
});

View File

@@ -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.

View File

@@ -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"),

View File

@@ -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",
});
},
};
},
};

View File

@@ -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, {});"),
],
});