summaryrefslogtreecommitdiffstats
path: root/tools/lint/eslint/eslint-plugin-mozilla/lib
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /tools/lint/eslint/eslint-plugin-mozilla/lib
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/eslint/eslint-plugin-mozilla/lib')
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js11
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js4
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js1
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js12
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js34
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-exported-symbols-as-used.js20
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-global-this.js2
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-mixing-eager-and-lazy.js2
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-multiple-getters-calls.js18
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-top-level-await.js4
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-isInstance.js3
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-static-import.js2
-rw-r--r--tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js2
13 files changed, 90 insertions, 25 deletions
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 c4d28594b5..036ed1bda3 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -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",
@@ -76,7 +77,7 @@ module.exports = {
"no-unused-vars": [
"error",
{
- args: "none",
+ argsIgnorePattern: "^_",
vars: "all",
},
],
@@ -142,7 +143,7 @@ module.exports = {
},
// When adding items to this file please check for effects on sub-directories.
- plugins: ["fetch-options", "html", "json", "no-unsanitized"],
+ plugins: ["html", "json", "no-unsanitized"],
// When adding items to this file please check for effects on all of toolkit
// and browser
@@ -163,10 +164,6 @@ module.exports = {
// Encourage the use of dot notation whenever possible.
"dot-notation": "error",
- // XXX This rule should be enabled, see Bug 1557040
- // No credentials submitted with fetch calls
- "fetch-options/no-fetch-credentials": "off",
-
// Maximum depth callbacks can be nested.
"max-nested-callbacks": ["error", 10],
@@ -317,7 +314,7 @@ module.exports = {
"no-unused-vars": [
"error",
{
- args: "none",
+ argsIgnorePattern: "^_",
vars: "local",
},
],
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
index d3c983999a..7701a0b2ca 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
@@ -29,7 +29,7 @@ module.exports = {
"no-unused-vars": [
"error",
{
- args: "none",
+ argsIgnorePattern: "^_",
vars: "local",
},
],
@@ -42,7 +42,7 @@ module.exports = {
"no-unused-vars": [
"error",
{
- args: "none",
+ argsIgnorePattern: "^_",
vars: "all",
},
],
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
index 241299e2d3..83fa01935e 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
@@ -57,6 +57,7 @@ const MAPPINGS = {
"browser/components/places/content/places-menupopup.js",
"shopping-sidebar.js":
"browser/components/shopping/content/shopping-sidebar.js",
+ "browser-sidebar.js": "browser/components/sidebar/browser-sidebar.js",
};
const globalScriptsRegExp =
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
index bbc1f9bed8..4d894b58cf 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/globals.js
@@ -634,8 +634,8 @@ module.exports = {
let globalScope;
let parser = {
- Program() {
- globalScope = context.getScope();
+ Program(node) {
+ globalScope = helpers.getScope(context, node);
},
};
let filename = context.getFilename();
@@ -651,10 +651,14 @@ module.exports = {
for (let type of Object.keys(GlobalsForNode.prototype)) {
parser[type] = function (node) {
if (type === "Program") {
- globalScope = context.getScope();
+ globalScope = helpers.getScope(context, node);
helpers.addGlobals(extraHTMLGlobals, globalScope);
}
- let globals = handler[type](node, context.getAncestors(), globalScope);
+ let globals = handler[type](
+ node,
+ helpers.getAncestors(context, node),
+ globalScope
+ );
helpers.addGlobals(
globals,
globalScope,
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
index 9ab51df37e..7d44b4b1b3 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -794,4 +794,38 @@ module.exports = {
}
return null;
},
+
+ /**
+ * Gets the scope for a node taking account of where the scope function
+ * is available (supports node versions earlier than 8.37.0).
+ *
+ * @param {object} context
+ * The context passed from ESLint.
+ * @param {object} node
+ * The node to get the scope for.
+ * returns {function}
+ * The getScope function object.
+ */
+ getScope(context, node) {
+ return context.sourceCode?.getScope
+ ? context.sourceCode.getScope(node)
+ : context.getScope();
+ },
+
+ /**
+ * Gets the ancestors for a node taking account of where the ancestors function
+ * is available (supports node versions earlier than 8.38.0).
+ *
+ * @param {object} context
+ * The context passed from ESLint.
+ * @param {object} node
+ * The node to get the scope for.
+ * returns {function}
+ * The getScope function object.
+ */
+ getAncestors(context, node) {
+ return context.sourceCode?.getAncestors
+ ? context.sourceCode.getAncestors(node)
+ : context.getAncestors();
+ },
};
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-exported-symbols-as-used.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-exported-symbols-as-used.js
index 3664374053..b632e3b632 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-exported-symbols-as-used.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-exported-symbols-as-used.js
@@ -19,16 +19,26 @@ function markArrayElementsAsUsed(context, node, expression) {
}
for (let element of expression.elements) {
- context.markVariableAsUsed(element.value);
+ context.markVariableAsUsed
+ ? context.markVariableAsUsed(element.value)
+ : context.sourceCode.markVariableAsUsed(element.value);
}
// Also mark EXPORTED_SYMBOLS as used.
- context.markVariableAsUsed("EXPORTED_SYMBOLS");
+ context.markVariableAsUsed
+ ? context.markVariableAsUsed("EXPORTED_SYMBOLS")
+ : context.sourceCode.markVariableAsUsed("EXPORTED_SYMBOLS");
}
// Ignore assignments not in the global scope, e.g. where special module
// definitions are required due to having different ways of importing files,
// e.g. osfile.
-function isGlobalScope(context) {
+function isGlobalScope(context, node) {
+ if (context.sourceCode?.getScope) {
+ let upper = context.sourceCode.getScope(node).upper;
+ // ESLint v9 uses a global scope object with type = "global". Earlier
+ // versions use a null upper scope.
+ return !upper || upper.type == "global";
+ }
return !context.getScope().upper;
}
@@ -55,14 +65,14 @@ module.exports = {
node.left.type === "MemberExpression" &&
node.left.object.type === "ThisExpression" &&
node.left.property.name === "EXPORTED_SYMBOLS" &&
- isGlobalScope(context)
+ isGlobalScope(context, node)
) {
markArrayElementsAsUsed(context, node, node.right);
}
},
VariableDeclaration(node) {
- if (!isGlobalScope(context)) {
+ if (!isGlobalScope(context, node)) {
return;
}
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
index ec4b5fd43d..1067a4befa 100644
--- 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
@@ -29,7 +29,7 @@ module.exports = {
create(context) {
return {
ThisExpression(node) {
- if (!helpers.getIsGlobalThis(context.getAncestors())) {
+ if (!helpers.getIsGlobalThis(helpers.getAncestors(context, node))) {
return;
}
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-mixing-eager-and-lazy.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-mixing-eager-and-lazy.js
index 5779a90afd..41ddc998a3 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-mixing-eager-and-lazy.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-mixing-eager-and-lazy.js
@@ -71,7 +71,7 @@ module.exports = {
(callerSource === "ChromeUtils.import" ||
callerSource === "ChromeUtils.importESModule") &&
helpers.getIsTopLevelAndUnconditionallyExecuted(
- context.getAncestors()
+ helpers.getAncestors(context, node)
)
) {
if (node.arguments.length < 1) {
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-multiple-getters-calls.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-multiple-getters-calls.js
index e6e37ad035..0e0f6e2e17 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-multiple-getters-calls.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-multiple-getters-calls.js
@@ -56,6 +56,24 @@ module.exports = {
return;
}
+ if (node.arguments.length >= 3) {
+ const options = node.arguments[2];
+ let globalOption = null;
+ if (options.type == "ObjectExpression") {
+ for (const prop of options.properties) {
+ if (
+ prop.type == "Property" &&
+ isIdentifier(prop.key, "global")
+ ) {
+ globalOption = helpers.getASTSource(prop.value);
+ }
+ }
+ }
+ if (globalOption) {
+ target += "+" + globalOption;
+ }
+ }
+
const parent = stmt.parent;
let targets;
if (parentToTargets.has(parent)) {
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-top-level-await.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-top-level-await.js
index dff7db0f9a..7356fe10bf 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-top-level-await.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-top-level-await.js
@@ -26,7 +26,7 @@ module.exports = {
create(context) {
return {
AwaitExpression(node) {
- if (!helpers.getIsTopLevelScript(context.getAncestors())) {
+ if (!helpers.getIsTopLevelScript(helpers.getAncestors(context, node))) {
return;
}
context.report({ node, messageId: "rejectTopLevelAwait" });
@@ -34,7 +34,7 @@ module.exports = {
ForOfStatement(node) {
if (
!node.await ||
- !helpers.getIsTopLevelScript(context.getAncestors())
+ !helpers.getIsTopLevelScript(helpers.getAncestors(context, node))
) {
return;
}
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-isInstance.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-isInstance.js
index ffd9bc9566..f6d6f5e5d3 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-isInstance.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-isInstance.js
@@ -11,6 +11,7 @@
const fs = require("fs");
const { maybeGetMemberPropertyName } = require("../helpers");
+const helpers = require("../helpers");
const privilegedGlobals = Object.keys(
require("../environments/privileged.js").globals
@@ -133,7 +134,7 @@ module.exports = {
const { operator, right } = node;
if (
operator === "instanceof" &&
- pointsToDOMInterface(context.getScope(), right)
+ pointsToDOMInterface(helpers.getScope(context, node), right)
) {
context.report({
node,
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-static-import.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-static-import.js
index 100b5682de..0a768e25d4 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-static-import.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/use-static-import.js
@@ -35,7 +35,7 @@ module.exports = {
node.init?.type != "CallExpression" ||
node.init?.callee?.type != "MemberExpression" ||
!context.getFilename().endsWith(".sys.mjs") ||
- !helpers.isTopLevel(context.getAncestors())
+ !helpers.isTopLevel(helpers.getAncestors(context, node))
) {
return;
}
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js
index 048ed17e3e..2be8840bf7 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/valid-lazy.js
@@ -225,7 +225,7 @@ module.exports = {
}
if (
helpers.getIsTopLevelAndUnconditionallyExecuted(
- context.getAncestors()
+ helpers.getAncestors(context, node)
)
) {
context.report({