summaryrefslogtreecommitdiffstats
path: root/tools/lint/eslint/eslint-plugin-mozilla/lib/rules
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lint/eslint/eslint-plugin-mozilla/lib/rules')
-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
8 files changed, 41 insertions, 12 deletions
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({