diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /tools/lint/eslint/eslint-plugin-mozilla/lib/rules | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/eslint/eslint-plugin-mozilla/lib/rules')
6 files changed, 77 insertions, 8 deletions
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js index 7a099ba340..daa327f916 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-browser-window-globals.js @@ -26,7 +26,7 @@ module.exports = { create(context) { return { - Program(node) { + Program() { let filePath = helpers.getAbsoluteFilePath(context); let relativePath = path.relative(helpers.rootDir, filePath); // We need to translate the path on Windows, due to the change diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js index e2b66ce8b0..c27ef25ce1 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-content-task-globals.js @@ -29,7 +29,7 @@ module.exports = { create(context) { return { "CallExpression[callee.object.name='ContentTask'][callee.property.name='spawn']": - function (node) { + function () { // testing/mochitest/BrowserTestUtils/content/content-task.js // This script is loaded as a sub script into a frame script. for (let [name, value] of Object.entries(frameScriptEnv.globals)) { @@ -37,7 +37,7 @@ module.exports = { } }, "CallExpression[callee.object.name='SpecialPowers'][callee.property.name='spawn']": - function (node) { + function () { for (let [name, value] of Object.entries(sandboxEnv.globals)) { helpers.addVarToScope(name, context.getScope(), value); } @@ -54,7 +54,7 @@ module.exports = { } }, "CallExpression[callee.object.name='SpecialPowers'][callee.property.name='spawnChrome']": - function (node) { + function () { for (let [name, value] of Object.entries(sandboxEnv.globals)) { helpers.addVarToScope(name, context.getScope(), value); } diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js index d4fa484b99..0405d9cd78 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/import-headjs-globals.js @@ -13,7 +13,7 @@ var fs = require("fs"); var helpers = require("../helpers"); var globals = require("../globals"); -function importHead(context, path, node) { +function importHead(context, path) { try { let stats = fs.statSync(path); if (!stats.isFile()) { 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 5d0e57e4c8..3664374053 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 @@ -49,7 +49,7 @@ module.exports = { create(context) { return { - AssignmentExpression(node, parents) { + AssignmentExpression(node) { if ( node.operator === "=" && node.left.type === "MemberExpression" && @@ -61,7 +61,7 @@ module.exports = { } }, - VariableDeclaration(node, parents) { + VariableDeclaration(node) { if (!isGlobalScope(context)) { return; } diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-more-globals.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-more-globals.js new file mode 100644 index 0000000000..921ead67bd --- /dev/null +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/no-more-globals.js @@ -0,0 +1,69 @@ +/** + * 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 globals = require("../globals"); + +const fs = require("fs"); + +module.exports = { + meta: { + docs: { + url: "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/rules/no-more-globals.html", + }, + messages: { + newGlobal: + "The global {{ name }} was not previously in this file, where new global variables are not permitted.", + removedGlobal: + "The global {{ name }} was expected to be defined in this file but isn't. Please remove it from the .globals file.", + missingGlobalsFile: + "This file has mozilla/no-more-globals enabled but has no .globals sibling file. Please create one.", + }, + schema: [], + type: "problem", + }, + + create(context) { + return { + Program(node) { + let filename = context.filename; + let code = context.sourceCode.getText(); + let currentGlobals = globals.getGlobalsForCode(code, {}, false); + let knownGlobals; + try { + knownGlobals = new Set( + JSON.parse(fs.readFileSync(filename + ".globals")) + ); + } catch (ex) { + context.report({ + node, + messageId: "missingGlobalsFile", + }); + return; + } + for (let { name } of currentGlobals) { + if (!knownGlobals.has(name)) { + context.report({ + node, + messageId: "newGlobal", + data: { name }, + }); + } + } + for (let known of knownGlobals) { + if (!currentGlobals.some(n => n.name == known)) { + context.report({ + node, + messageId: "removedGlobal", + data: { name: known }, + }); + } + } + }, + }; + }, +}; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-globalThis-modification.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-globalThis-modification.js index 13052db80c..f14fdcd795 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-globalThis-modification.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/reject-globalThis-modification.js @@ -42,7 +42,7 @@ module.exports = { create(context) { return { - AssignmentExpression(node, parents) { + AssignmentExpression(node) { let target = node.left; while (target.type === "MemberExpression") { target = target.object; |