tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 3b73e695bd9aa9b0dac83745fc8ee8c3aa2a6bd2
parent 86e3736350a9c984f29acbe70e7d6bede87ddf38
Author: Mark Banner <standard8@mozilla.com>
Date:   Fri, 21 Nov 2025 16:13:48 +0000

Bug 2000186 - Change eslint-plugin-mozilla's configurations to use the flat config format directly. r=frontend-codestyle-reviewers,mossop

This cleans up from the previously removed legacy configuration.

Differential Revision: https://phabricator.services.mozilla.com/D272624

Diffstat:
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.mjs | 113++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.mjs | 38++++++++++++++++++++------------------
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.mjs | 8+++++++-
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/mochitest-test.mjs | 16++++++++--------
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.mjs | 425++++++++++++++++++++++++++++++++++++++++---------------------------------------
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/require-jsdoc.mjs | 4+++-
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/valid-jsdoc.mjs | 4+++-
Mtools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.mjs | 17+++++++++++++----
Mtools/lint/eslint/eslint-plugin-mozilla/lib/index.mjs | 93+++++++++++--------------------------------------------------------------------
9 files changed, 338 insertions(+), 380 deletions(-)

diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/browser-test.mjs @@ -4,66 +4,67 @@ // Parent config file for all browser-chrome files. -export default { - env: { - browser: true, - "mozilla/browser-window": true, - "mozilla/simpletest": true, - }, +import globals from "globals"; +import browserWindow from "../environments/browser-window.mjs"; +import simpleTest from "../environments/simpletest.mjs"; - // All globals made available in the test environment. - globals: { - // `$` is defined in SimpleTest.js - $: "readonly", - Assert: "readonly", - BrowserTestUtils: "readonly", - ContentTask: "readonly", - EventUtils: "readonly", - IOUtils: "readonly", - PathUtils: "readonly", - PromiseDebugging: "readonly", - SpecialPowers: "readonly", - TestUtils: "readonly", - addLoadEvent: "readonly", - add_setup: "readonly", - add_task: "readonly", - afterEach: "readonly", - beforeEach: "readonly", - content: "readonly", - describe: "readonly", - executeSoon: "readonly", - expectUncaughtException: "readonly", - export_assertions: "readonly", - extractJarToTmp: "readonly", - finish: "readonly", - gTestPath: "readonly", - getChromeDir: "readonly", - getJar: "readonly", - getResolvedURI: "readonly", - getRootDirectory: "readonly", - getTestFilePath: "readonly", - ignoreAllUncaughtExceptions: "readonly", - info: "readonly", - is: "readonly", - isnot: "readonly", - it: "readonly", - ok: "readonly", - record: "readonly", - registerCleanupFunction: "readonly", - requestLongerTimeout: "readonly", - stringContains: "readonly", - stringMatches: "readonly", - testSignal: "readonly", - todo: "readonly", - todo_is: "readonly", - todo_isnot: "readonly", - waitForClipboard: "readonly", - waitForExplicitFinish: "readonly", - waitForFocus: "readonly", +export default { + languageOptions: { + globals: { + ...globals.browser, + ...browserWindow.globals, + ...simpleTest.globals, + // `$` is defined in SimpleTest.js + $: "readonly", + Assert: "readonly", + BrowserTestUtils: "readonly", + ContentTask: "readonly", + EventUtils: "readonly", + IOUtils: "readonly", + PathUtils: "readonly", + PromiseDebugging: "readonly", + SpecialPowers: "readonly", + TestUtils: "readonly", + addLoadEvent: "readonly", + add_setup: "readonly", + add_task: "readonly", + afterEach: "readonly", + beforeEach: "readonly", + content: "readonly", + describe: "readonly", + executeSoon: "readonly", + expectUncaughtException: "readonly", + export_assertions: "readonly", + extractJarToTmp: "readonly", + finish: "readonly", + gTestPath: "readonly", + getChromeDir: "readonly", + getJar: "readonly", + getResolvedURI: "readonly", + getRootDirectory: "readonly", + getTestFilePath: "readonly", + ignoreAllUncaughtExceptions: "readonly", + info: "readonly", + is: "readonly", + isnot: "readonly", + it: "readonly", + ok: "readonly", + record: "readonly", + registerCleanupFunction: "readonly", + requestLongerTimeout: "readonly", + stringContains: "readonly", + stringMatches: "readonly", + testSignal: "readonly", + todo: "readonly", + todo_is: "readonly", + todo_isnot: "readonly", + waitForClipboard: "readonly", + waitForExplicitFinish: "readonly", + waitForFocus: "readonly", + }, }, name: "mozilla/browser-test", - plugins: ["mozilla"], rules: { "mozilla/no-addtask-setup": "error", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/chrome-test.mjs @@ -4,29 +4,31 @@ // Parent config file for all mochitest files. +import globals from "globals"; +import browserWindow from "../environments/browser-window.mjs"; + export default { - env: { - browser: true, - "mozilla/browser-window": true, - }, + languageOptions: { + globals: { + // All globals made available in the test environment. + ...globals.browser, + ...browserWindow.globals, - // All globals made available in the test environment. - globals: { - // SpecialPowers is injected into the window object via SimpleTest.js - SpecialPowers: "readonly", - afterEach: "readonly", - beforeEach: "readonly", - describe: "readonly", - extractJarToTmp: "readonly", - getChromeDir: "readonly", - getJar: "readonly", - getResolvedURI: "readonly", - getRootDirectory: "readonly", - it: "readonly", + // SpecialPowers is injected into the window object via SimpleTest.js + SpecialPowers: "readonly", + afterEach: "readonly", + beforeEach: "readonly", + describe: "readonly", + extractJarToTmp: "readonly", + getChromeDir: "readonly", + getJar: "readonly", + getResolvedURI: "readonly", + getRootDirectory: "readonly", + it: "readonly", + }, }, name: "mozilla/chrome-test", - plugins: ["mozilla"], rules: { // We mis-predict globals for HTML test files in directories shared diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/general-test.mjs @@ -6,9 +6,15 @@ // This should be applied by the configuration before any other test // configurations. +import noUnsanitizedPlugin from "eslint-plugin-no-unsanitized"; +import sdlPlugin from "@microsoft/eslint-plugin-sdl"; + export default { name: "mozilla/general-test", - plugins: ["mozilla", "@microsoft/sdl", "no-unsanitized"], + plugins: { + "@microsoft/sdl": sdlPlugin, + "no-unsanitized": noUnsanitizedPlugin, + }, rules: { // No using of insecure url, so no http urls. diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/mochitest-test.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/mochitest-test.mjs @@ -3,20 +3,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // Parent config file for all mochitest files. +import globals from "globals"; export default { - env: { - browser: true, - }, + languageOptions: { + globals: { + // All globals made available in the test environment. + ...globals.browser, - // All globals made available in the test environment. - globals: { - // SpecialPowers is injected into the window object via SimpleTest.js - SpecialPowers: "readonly", + // SpecialPowers is injected into the window object via SimpleTest.js + SpecialPowers: "readonly", + }, }, name: "mozilla/mochitest-test", - plugins: ["mozilla"], rules: { // Turn off no-define-cc-etc for mochitests as these don't have Cc etc defined in the diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.mjs @@ -2,8 +2,13 @@ * 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/. */ +import globals from "globals"; import js from "@eslint/js"; import helpers from "../helpers.mjs"; +import privileged from "../environments/privileged.mjs"; +import specific from "../environments/specific.mjs"; +import sysmjs from "../environments/sysmjs.mjs"; +import sjs from "../environments/sjs.mjs"; const { allFileExtensions } = helpers; @@ -39,214 +44,234 @@ const { allFileExtensions } = helpers; * - This doesn't reveal any actual errors, and is a lot of work to address. */ -const coreRules = { - // When adding items to this file please check for effects on all of toolkit - // and browser - rules: { - // This may conflict with prettier, so we turn it off. - "arrow-body-style": "off", - - // Warn about cyclomatic complexity in functions. - // XXX Get this down to 20? - complexity: ["error", 34], - - // Functions must always return something or nothing - "consistent-return": "error", - - // Encourage the use of dot notation whenever possible. - "dot-notation": "error", - - // Maximum depth callbacks can be nested. - "max-nested-callbacks": ["error", 10], - - "mozilla/avoid-removeChild": "error", - "mozilla/import-browser-window-globals": "error", - "mozilla/import-globals": "error", - "mozilla/no-compare-against-boolean-literals": "error", - "mozilla/no-cu-reportError": "error", - "mozilla/no-define-cc-etc": "error", - "mozilla/no-throw-cr-literal": "error", - "mozilla/no-useless-parameters": "error", - "mozilla/no-useless-removeEventListener": "error", - "mozilla/prefer-boolean-length-check": "error", - "mozilla/prefer-formatValues": "error", - "mozilla/reject-addtask-only": "error", - "mozilla/reject-importGlobalProperties": ["error", "allownonwebidl"], - "mozilla/reject-multiple-await": "error", - "mozilla/reject-multiple-getters-calls": "error", - "mozilla/reject-scriptableunicodeconverter": "warn", - "mozilla/rejects-requires-await": "error", - "mozilla/use-cc-etc": "error", - "mozilla/use-chromeutils-generateqi": "error", - "mozilla/use-console-createInstance": "error", - "mozilla/use-default-preference-values": "error", - "mozilla/use-includes-instead-of-indexOf": "error", - "mozilla/use-isInstance": "error", - "mozilla/use-ownerGlobal": "error", - "mozilla/use-returnValue": "error", - "mozilla/use-services": "error", - "mozilla/valid-lazy": "error", - "mozilla/valid-services": "error", - - // Use [] instead of Array() - "no-array-constructor": "error", - - // Disallow use of arguments.caller or arguments.callee. - "no-caller": "error", - - // Disallow the use of console, except for errors and warnings. - "no-console": ["error", { allow: ["createInstance", "error", "warn"] }], - - // Disallows expressions where the operation doesn't affect the value. - // TODO: This is enabled by default in ESLint's v9 recommended configuration. - "no-constant-binary-expression": "error", - - // If an if block ends with a return no need for an else block - "no-else-return": "error", - - // No empty statements - "no-empty": ["error", { allowEmptyCatch: true }], - - // Disallow empty static blocks. - // This rule will be a recommended rule in ESLint v9 so may be removed - // when we upgrade to that. - "no-empty-static-block": "error", - - // Disallow eval and setInteral/setTimeout with strings - "no-eval": "error", - - // Disallow unnecessary calls to .bind() - "no-extra-bind": "error", - - // Disallow fallthrough of case statements - "no-fallthrough": [ - "error", - { - // The eslint rule doesn't allow for case-insensitive regex option. - // The following pattern allows for a dash between "fall through" as - // well as alternate spelling of "fall thru". The pattern also allows - // for an optional "s" at the end of "fall" ("falls through"). - commentPattern: - "[Ff][Aa][Ll][Ll][Ss]?[\\s-]?([Tt][Hh][Rr][Oo][Uu][Gg][Hh]|[Tt][Hh][Rr][Uu])", +import noUnsanitizedPlugin from "eslint-plugin-no-unsanitized"; +import promisePlugin from "eslint-plugin-promise"; + +export default [ + { + files: [`**/*.{${allFileExtensions.join(",")}}`], + + languageOptions: { + // If this changes, ensure the version in `legacyConfig` is updated, as well + // as the return value of `helpers.getECMAVersion()`. + ecmaVersion: "latest", + globals: { + // Temporal is currently a stage 3 ECMA proposal, and won't be in the + // "latest" ecmaVersion in ESLint until it reaches stage 4. + Temporal: "readonly", }, - ], + }, - // Disallow eval and setInteral/setTimeout with strings - "no-implied-eval": "error", + name: "mozilla/recommended/main-rules", - // See explicit decisions at top of file. - "no-inner-declarations": "off", + plugins: { "no-unsanitized": noUnsanitizedPlugin, promise: promisePlugin }, - // Disallow the use of the __iterator__ property - "no-iterator": "error", + rules: { + ...js.configs.recommended.rules, + // This may conflict with prettier, so we turn it off. + "arrow-body-style": "off", + + // Warn about cyclomatic complexity in functions. + // XXX Get this down to 20? + complexity: ["error", 34], + + // Functions must always return something or nothing + "consistent-return": "error", + + // Encourage the use of dot notation whenever possible. + "dot-notation": "error", + + // Maximum depth callbacks can be nested. + "max-nested-callbacks": ["error", 10], + + "mozilla/avoid-removeChild": "error", + "mozilla/import-browser-window-globals": "error", + "mozilla/import-globals": "error", + "mozilla/no-compare-against-boolean-literals": "error", + "mozilla/no-cu-reportError": "error", + "mozilla/no-define-cc-etc": "error", + "mozilla/no-throw-cr-literal": "error", + "mozilla/no-useless-parameters": "error", + "mozilla/no-useless-removeEventListener": "error", + "mozilla/prefer-boolean-length-check": "error", + "mozilla/prefer-formatValues": "error", + "mozilla/reject-addtask-only": "error", + "mozilla/reject-importGlobalProperties": ["error", "allownonwebidl"], + "mozilla/reject-multiple-await": "error", + "mozilla/reject-multiple-getters-calls": "error", + "mozilla/reject-scriptableunicodeconverter": "warn", + "mozilla/rejects-requires-await": "error", + "mozilla/use-cc-etc": "error", + "mozilla/use-chromeutils-generateqi": "error", + "mozilla/use-console-createInstance": "error", + "mozilla/use-default-preference-values": "error", + "mozilla/use-includes-instead-of-indexOf": "error", + "mozilla/use-isInstance": "error", + "mozilla/use-ownerGlobal": "error", + "mozilla/use-returnValue": "error", + "mozilla/use-services": "error", + "mozilla/valid-lazy": "error", + "mozilla/valid-services": "error", + + // Use [] instead of Array() + "no-array-constructor": "error", + + // Disallow use of arguments.caller or arguments.callee. + "no-caller": "error", + + // Disallow the use of console, except for errors and warnings. + "no-console": ["error", { allow: ["createInstance", "error", "warn"] }], + + // Disallows expressions where the operation doesn't affect the value. + // TODO: This is enabled by default in ESLint's v9 recommended configuration. + "no-constant-binary-expression": "error", + + // If an if block ends with a return no need for an else block + "no-else-return": "error", + + // No empty statements + "no-empty": ["error", { allowEmptyCatch: true }], + + // Disallow empty static blocks. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-empty-static-block": "error", + + // Disallow eval and setInteral/setTimeout with strings + "no-eval": "error", + + // Disallow unnecessary calls to .bind() + "no-extra-bind": "error", + + // Disallow fallthrough of case statements + "no-fallthrough": [ + "error", + { + // The eslint rule doesn't allow for case-insensitive regex option. + // The following pattern allows for a dash between "fall through" as + // well as alternate spelling of "fall thru". The pattern also allows + // for an optional "s" at the end of "fall" ("falls through"). + commentPattern: + "[Ff][Aa][Ll][Ll][Ss]?[\\s-]?([Tt][Hh][Rr][Oo][Uu][Gg][Hh]|[Tt][Hh][Rr][Uu])", + }, + ], - // No labels - "no-labels": "error", + // Disallow eval and setInteral/setTimeout with strings + "no-implied-eval": "error", - // Disallow unnecessary nested blocks - "no-lone-blocks": "error", + // See explicit decisions at top of file. + "no-inner-declarations": "off", - // No single if block inside an else block - "no-lonely-if": "error", + // Disallow the use of the __iterator__ property + "no-iterator": "error", - // Nested ternary statements are confusing - "no-nested-ternary": "error", + // No labels + "no-labels": "error", - // Disallow new operators with global non-constructor functions. - // This rule will be a recommended rule in ESLint v9 so may be removed - // when we upgrade to that. - "no-new-native-nonconstructor": "error", + // Disallow unnecessary nested blocks + "no-lone-blocks": "error", - // Disallow use of new wrappers - "no-new-wrappers": "error", + // No single if block inside an else block + "no-lonely-if": "error", - // Use {} instead of new Object(), unless arguments are passed. - "no-object-constructor": "error", + // Nested ternary statements are confusing + "no-nested-ternary": "error", - // We don't want this, see bug 1551829 - "no-prototype-builtins": "off", + // Disallow new operators with global non-constructor functions. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-new-native-nonconstructor": "error", - // Disable builtinGlobals for no-redeclare as this conflicts with our - // globals declarations especially for browser window. - "no-redeclare": ["error", { builtinGlobals: false }], + // Disallow use of new wrappers + "no-new-wrappers": "error", - // Disallow use of event global. - "no-restricted-globals": ["error", "event"], + // Use {} instead of new Object(), unless arguments are passed. + "no-object-constructor": "error", - // No unnecessary comparisons - "no-self-compare": "error", + // We don't want this, see bug 1551829 + "no-prototype-builtins": "off", - // No comma sequenced statements - "no-sequences": "error", + // Disable builtinGlobals for no-redeclare as this conflicts with our + // globals declarations especially for browser window. + "no-redeclare": ["error", { builtinGlobals: false }], - // No declaring variables from an outer scope - "no-shadow": "error", + // Disallow use of event global. + "no-restricted-globals": ["error", "event"], - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", + // No unnecessary comparisons + "no-self-compare": "error", - // Disallow the use of Boolean literals in conditional expressions. - "no-unneeded-ternary": "error", + // No comma sequenced statements + "no-sequences": "error", - // No unsanitized use of innerHTML=, document.write() etc. - // cf. https://github.com/mozilla/eslint-plugin-no-unsanitized#rule-details - "no-unsanitized/method": "error", - "no-unsanitized/property": "error", + // No declaring variables from an outer scope + "no-shadow": "error", - // Disallow unused private class members. - // This rule will be a recommended rule in ESLint v9 so may be removed - // when we upgrade to that. - "no-unused-private-class-members": "error", + // Disallow throwing literals (eg. throw "error" instead of + // throw new Error("error")). + "no-throw-literal": "error", - // No declaring variables that are never used - "no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - caughtErrors: "none", - vars: "local", - }, - ], + // Disallow the use of Boolean literals in conditional expressions. + "no-unneeded-ternary": "error", + + // No unsanitized use of innerHTML=, document.write() etc. + // cf. https://github.com/mozilla/eslint-plugin-no-unsanitized#rule-details + "no-unsanitized/method": "error", + "no-unsanitized/property": "error", + + // Disallow unused private class members. + // This rule will be a recommended rule in ESLint v9 so may be removed + // when we upgrade to that. + "no-unused-private-class-members": "error", + + // No declaring variables that are never used + "no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + caughtErrors: "none", + vars: "local", + }, + ], - // No using variables before defined - // "no-use-before-define": ["error", "nofunc"], + // No using variables before defined + // "no-use-before-define": ["error", "nofunc"], - // Disallow unnecessary .call() and .apply() - "no-useless-call": "error", + // Disallow unnecessary .call() and .apply() + "no-useless-call": "error", - // Don't concatenate string literals together (unless they span multiple - // lines) - "no-useless-concat": "error", + // Don't concatenate string literals together (unless they span multiple + // lines) + "no-useless-concat": "error", - // See explicit decisions at top of file. - "no-useless-escape": "off", + // See explicit decisions at top of file. + "no-useless-escape": "off", - // Disallow redundant return statements - "no-useless-return": "error", + // Disallow redundant return statements + "no-useless-return": "error", - // Require object-literal shorthand with ES6 method syntax - "object-shorthand": ["error", "always", { avoidQuotes: true }], + // Require object-literal shorthand with ES6 method syntax + "object-shorthand": ["error", "always", { avoidQuotes: true }], - // This may conflict with prettier, so turn it off. - "prefer-arrow-callback": "off", + // This may conflict with prettier, so turn it off. + "prefer-arrow-callback": "off", - // Not passing anything to .catch/.then doesn't work, error: - "promise/valid-params": "error", + // Not passing anything to .catch/.then doesn't work, error: + "promise/valid-params": "error", + }, }, -}; - -const extraRules = [ { - // System mjs files files are not loaded in the browser scope, - // so we turn that off for those. Though we do have our own special - // environment for them. - env: { - "mozilla/privileged": true, - "mozilla/specific": true, - "mozilla/sysmjs": true, - }, files: ["**/*.sys.mjs"], + languageOptions: { + globals: { + // System mjs files files are not loaded in the browser scope, + // so we don't use that environment. Though we do have our own special + // environment for them. + ...privileged.globals, + ...specific.globals, + ...sysmjs.globals, + }, + }, name: "mozilla/recommended/system-modules", rules: { "mozilla/lazy-getter-object-name": "error", @@ -295,10 +320,12 @@ const extraRules = [ }, { files: ["**/*.mjs", "**/*.jsx"], - name: "mozilla/recommended/module-only", - parserOptions: { - sourceType: "module", + languageOptions: { + parserOptions: { + sourceType: "module", + }, }, + name: "mozilla/recommended/module-only", rules: { "mozilla/use-static-import": "error", // This rule defaults to not allowing "use strict" in module files since @@ -307,10 +334,10 @@ const extraRules = [ }, }, { - env: { - "mozilla/sjs": true, - }, files: ["**/*.sjs"], + languageOptions: { + globals: { ...sjs.globals }, + }, name: "mozilla/recommended/sjs", rules: { // For sjs files, reject everything as we should update the sandbox @@ -319,27 +346,27 @@ const extraRules = [ }, }, { - env: { - worker: true, - }, files: [ // Most files should use the `.worker.` format to be consistent with // other items like `.sys.mjs`, but we allow simply calling the file // "worker" as well. "**/?(*.)worker.?(m)js", ], + languageOptions: { + globals: { ...globals.worker }, + }, name: "mozilla/recommended/worker", }, { - env: { - serviceworker: true, - }, files: [ // Most files should use the `.serviceworker.` format to be consistent // with other items like `.sys.mjs`, but we allow simply calling the file // "serviceworker" as well. "**/?(*.)serviceworker.?(m)js", ], + languageOptions: { + globals: { ...globals.serviceworker }, + }, name: "mozilla/recommended/serviceworker", }, { @@ -349,27 +376,3 @@ const extraRules = [ rules: { "mozilla/import-globals": "off" }, }, ]; - -export default [ - // Note: plugins are added in the top-level index.js file. This is to avoid - // needing to import them multiple times for different configs. - { - files: [`**/*.{${allFileExtensions.join(",")}}`], - languageOptions: { - // If this changes, ensure the version in `legacyConfig` is updated, as well - // as the return value of `helpers.getECMAVersion()`. - ecmaVersion: "latest", - globals: { - // Temporal is currently a stage 3 ECMA proposal, and won't be in the - // "latest" ecmaVersion in ESLint until it reaches stage 4. - Temporal: "readonly", - }, - }, - name: "mozilla/recommended/main-rules", - rules: { - ...js.configs.recommended.rules, - ...coreRules.rules, - }, - }, - ...structuredClone(extraRules), -]; diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/require-jsdoc.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/require-jsdoc.mjs @@ -2,9 +2,11 @@ * 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/. */ +import jsdoc from "eslint-plugin-jsdoc"; + export default { name: "mozilla/require-jsdoc", - plugins: ["jsdoc"], + plugins: { jsdoc }, rules: { "jsdoc/require-jsdoc": [ diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/valid-jsdoc.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/valid-jsdoc.mjs @@ -2,9 +2,11 @@ * 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/. */ +import jsdoc from "eslint-plugin-jsdoc"; + export default { name: "mozilla/valid-jsdoc", - plugins: ["jsdoc"], + plugins: { jsdoc }, rules: { "jsdoc/check-access": "error", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.mjs @@ -2,16 +2,25 @@ * 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/. */ +import privileged from "../environments/privileged.mjs"; +import xpcshell from "../environments/xpcshell.mjs"; +import sdlPlugin from "@microsoft/eslint-plugin-sdl"; + // Parent config file for all xpcshell files. export default { - env: { - "mozilla/privileged": true, - "mozilla/xpcshell": true, + languageOptions: { + globals: { + ...privileged.globals, + ...xpcshell.globals, + }, }, name: "mozilla/xpcshell-test", - plugins: ["mozilla", "@microsoft/sdl"], + + plugins: { + "@microsoft/sdl": sdlPlugin, + }, rules: { // Turn off no-insecure-url as it is not considered necessary for xpcshell diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/index.mjs b/tools/lint/eslint/eslint-plugin-mozilla/lib/index.mjs @@ -6,15 +6,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import globals from "globals"; import helpers from "./helpers.mjs"; import packageData from "../package.json" with { type: "json" }; -import noUnsanitizedPlugin from "eslint-plugin-no-unsanitized"; -import sdlPlugin from "@microsoft/eslint-plugin-sdl"; -import promisePlugin from "eslint-plugin-promise"; -import jsdocPlugin from "eslint-plugin-jsdoc"; - let { allFileExtensions, turnOff } = helpers; let plugin = { @@ -174,98 +168,37 @@ let plugin = { turnOff, }; -/** - * Clones a flat configuration section, adjusting fields so that ESLint won't - * fail. - * - * @param {object} section - * The section to clone. - * @returns {object} - * The cloned section. - */ -function cloneFlatSection(section) { - let config = structuredClone(section); - - // We assume all parts of the flat config need the plugins defined. In - // practice, they only need to be defined where they are used, but for - // now this is simpler. - config.plugins = { - mozilla: plugin, - "no-unsanitized": noUnsanitizedPlugin, - "@microsoft/sdl": sdlPlugin, - promise: promisePlugin, - jsdoc: jsdocPlugin, - }; - if (!config.languageOptions) { - config.languageOptions = {}; - } - - if (config.globals) { - config.languageOptions.globals = { ...config.globals }; - delete config.globals; +function addThisPlugin(section) { + if (!section.plugins) { + section.plugins = {}; } - - // Handle changing the location of the sourceType. - if (config.parserOptions?.sourceType) { - config.languageOptions.sourceType = config.parserOptions.sourceType; - } - if (config.parserOptions?.ecmaFeatures) { - config.languageOptions.parserOptions = { - ecmaFeatures: config.parserOptions.ecmaFeatures, - }; - } - delete config.parserOptions; - - // Convert any environments into a list of globals. - for (let [key, value] of Object.entries(config.env ?? {})) { - if (!value) { - throw new Error( - "Removing environments is not supported by eslint-plugin-mozilla" - ); - } - if (!config.languageOptions.globals) { - config.languageOptions.globals = {}; - } - if (key.startsWith("mozilla/")) { - config.languageOptions.globals = { - ...config.languageOptions.globals, - ...plugin.environments[key.substring("mozilla/".length)].globals, - }; - } else { - config.languageOptions.globals = { - ...config.languageOptions.globals, - ...globals[key], - }; - } - } - delete config.env; - - return config; + section.plugins.mozilla = plugin; + return section; } plugin.configs = { - "flat/browser-test": cloneFlatSection( + "flat/browser-test": addThisPlugin( (await import("./configs/browser-test.mjs")).default ), - "flat/chrome-test": cloneFlatSection( + "flat/chrome-test": addThisPlugin( (await import("./configs/chrome-test.mjs")).default ), - "flat/general-test": cloneFlatSection( + "flat/general-test": addThisPlugin( (await import("./configs/general-test.mjs")).default ), - "flat/mochitest-test": cloneFlatSection( + "flat/mochitest-test": addThisPlugin( (await import("./configs/mochitest-test.mjs")).default ), "flat/recommended": (await import("./configs/recommended.mjs")).default.map( - section => cloneFlatSection(section) + section => addThisPlugin(section) ), - "flat/require-jsdoc": cloneFlatSection( + "flat/require-jsdoc": addThisPlugin( (await import("./configs/require-jsdoc.mjs")).default ), - "flat/valid-jsdoc": cloneFlatSection( + "flat/valid-jsdoc": addThisPlugin( (await import("./configs/valid-jsdoc.mjs")).default ), - "flat/xpcshell-test": cloneFlatSection( + "flat/xpcshell-test": addThisPlugin( (await import("./configs/xpcshell-test.mjs")).default ), };