Bug 1889087 - Enable ESLint rule mozilla/reject-chromeutils-import on devtools as well. r=arai,devtools-reviewers,profiler-reviewers,julienw

Differential Revision: https://phabricator.services.mozilla.com/D206349
This commit is contained in:
Mark Banner 2024-04-02 19:05:48 +00:00
parent abf84fd282
commit 5f19d766d1
6 changed files with 6 additions and 69 deletions

View File

@ -2206,10 +2206,7 @@ module.exports = {
},
},
{
files: ["**"],
excludedFiles: [
// Devtools code, see bug 1525652.
"devtools/**",
files: [
// Tests specific to JSM
"dom/encoding/test/test_stringencoding.xhtml",
"dom/url/tests/test_bug883784.xhtml",
@ -2224,7 +2221,7 @@ module.exports = {
"js/xpconnect/loader/XPCOMUtils.sys.mjs",
],
rules: {
"mozilla/reject-chromeutils-import": "error",
"mozilla/reject-chromeutils-import": "off",
},
},
{

View File

@ -1,55 +0,0 @@
/* 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/. */
// @ts-check
"use strict";
/**
* TypeScript can't understand the lazyRequireGetter mechanism, due to how it defines
* properties as a getter. This function, instead provides lazy loading in a
* TypeScript-friendly manner. It applies the lazy load memoization to each property
* of the provided object.
*
* Example usage:
*
* const lazy = createLazyLoaders({
* moduleA: () => require("module/a"),
* moduleB: () => require("module/b"),
* });
*
* Later:
*
* const moduleA = lazy.moduleA();
* const { objectInModuleB } = lazy.moduleB();
*
* @template {{ [key: string]: () => any }} T
* @param {T} definition - An object where each property has a function that loads a module.
* @returns {T} - The load memoized version of T.
*/
function createLazyLoaders(definition) {
/** @type {any} */
const result = {};
for (const [key, callback] of Object.entries(definition)) {
/** @type {any} */
let cache;
result[key] = () => {
if (cache === undefined) {
cache = callback();
}
return cache;
};
}
return result;
}
// Provide an exports object for the JSM to be properly read by TypeScript.
/** @type {any} */
var module = {};
module.exports = {
createLazyLoaders,
};
// Object.keys() confuses the linting which expects a static array expression.
// eslint-disable-next-line
var EXPORTED_SYMBOLS = Object.keys(module.exports);

View File

@ -37,9 +37,6 @@ function* getOwnIdentifiers(x) {
function isJSONURI(uri) {
return uri.endsWith(".json");
}
function isJSMURI(uri) {
return uri.endsWith(".jsm");
}
function isSYSMJSURI(uri) {
return uri.endsWith(".sys.mjs");
}
@ -218,7 +215,7 @@ function load(loader, module) {
// Utility function to normalize module `uri`s so they have `.js` extension.
function normalizeExt(uri) {
if (isJSURI(uri) || isJSONURI(uri) || isJSMURI(uri) || isSYSMJSURI(uri)) {
if (isJSURI(uri) || isJSONURI(uri) || isSYSMJSURI(uri)) {
return uri;
}
return uri + ".js";
@ -336,9 +333,6 @@ export function Require(loader, requirer) {
// If module is already cached by loader then just use it.
if (uri in modules) {
module = modules[uri];
} else if (isJSMURI(uri)) {
module = modules[uri] = Module(requirement, uri);
module.exports = ChromeUtils.import(uri);
} else if (isSYSMJSURI(uri)) {
module = modules[uri] = Module(requirement, uri);
module.exports = ChromeUtils.importESModule(uri, {

View File

@ -55,6 +55,7 @@ module.exports = {
files: ["**/*.sys.mjs", "**/*.jsm"],
rules: {
"mozilla/lazy-getter-object-name": "error",
"mozilla/reject-chromeutils-import": "error",
"mozilla/reject-eager-module-in-lazy-getter": "error",
"mozilla/reject-global-this": "error",
"mozilla/reject-globalThis-modification": "error",

View File

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "3.7.1",
"version": "3.7.2",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "3.7.1",
"version": "3.7.2",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",