Bug 1881701 - Change new .eslintrc.mjs files to modules (misc), and export as flat config. r=frontend-codestyle-reviewers,webdriver-reviewers,perftest-reviewers,geckoview-reviewers,devtools-reviewers,sync-reviewers,android-reviewers,mossop,spidermonkey-reviewers,Gijs,ohall,whimboo,nchevobbe,arai,sparky,skhamis,webcompat-reviewers,twisniewski

Differential Revision: https://phabricator.services.mozilla.com/D249951
This commit is contained in:
Mark Banner 2025-05-24 17:08:08 +00:00 committed by mbanner@mozilla.com
parent 8b3069fa80
commit f29a0c8d41
40 changed files with 809 additions and 725 deletions

View file

@ -1,6 +1,9 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
rules: {
"mozilla/no-aArgs": "error",
"mozilla/reject-importGlobalProperties": ["error", "everything"],
@ -24,4 +27,5 @@ module.exports = {
yoda: "error",
"no-undef-init": "error",
},
};
},
];

View file

@ -1,14 +1,16 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
rules: {
// XXX These are rules that are enabled in the recommended configuration, but
// disabled here due to failures when initially implemented. They should be
// removed (and hence enabled) at some stage.
"no-nested-ternary": "off",
},
overrides: [
},
{
files: [
// Bug 1602061 TODO: These tests access DOM elements via
@ -20,5 +22,4 @@ module.exports = {
"no-undef": "off",
},
},
],
};
];

View file

@ -1,15 +1,15 @@
"use strict";
/* 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/. */
module.exports = {
overrides: [
export default [
{
// eslint-plugin-html doesn't automatically detect module sections in
// html files. Enable these as a module here. JavaScript files can use
// the mjs extension.
files: ["*.html"],
parserOptions: {
files: ["**/*.html"],
languageOptions: {
sourceType: "module",
},
},
],
};
];

View file

@ -2,13 +2,15 @@
* 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";
module.exports = {
export default [
{
languageOptions: {
globals: {
Assert: true,
exported_symbols: true,
require_module: true,
Utils: true,
},
};
},
},
];

View file

@ -3,10 +3,12 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
import globals from "globals";
module.exports = {
env: {
worker: true,
export default [
{
languageOptions: {
globals: globals.worker,
},
};
},
];

View file

@ -3,10 +3,12 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
import globals from "globals";
module.exports = {
env: {
worker: true,
export default [
{
languageOptions: {
globals: globals.worker,
},
};
},
];

View file

@ -1,8 +1,12 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
// Globals from mediasource.js. We use false to indicate they should not
// be overwritten in scripts.
languageOptions: {
globals: {
addMSEPrefs: false,
fetchAndLoad: false,
@ -20,9 +24,11 @@ module.exports = {
wait: false,
waitUntilTime: false,
},
},
// Use const/let instead of var for tighter scoping, avoiding redeclaration
rules: {
"no-var": "error",
"prefer-const": "error",
},
};
},
];

View file

@ -3,19 +3,12 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
import globals from "globals";
module.exports = {
env: {
worker: true,
},
overrides: [
export default [
{
files: ["head.js"],
env: {
worker: true,
languageOptions: {
globals: globals.worker,
},
},
],
};
];

View file

@ -2,48 +2,15 @@
* 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";
import spidermonkeyJS from "eslint-plugin-spidermonkey-js";
import mozilla from "eslint-plugin-mozilla";
import globals from "globals";
module.exports = {
plugins: ["spidermonkey-js"],
overrides: [
export default [
{
files: ["*.js"],
excludedFiles: ".eslintrc.js",
plugins: { "spidermonkey-js": spidermonkeyJS },
files: ["**/*.js"],
processor: "spidermonkey-js/processor",
env: {
// Disable all built-in environments.
node: false,
browser: false,
builtin: false,
// We need to explicitly disable the default environments added from
// "tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js".
es2021: false,
"mozilla/privileged": false,
"mozilla/specific": false,
// Enable SpiderMonkey's self-hosted environment.
"spidermonkey-js/environment": true,
},
parserOptions: {
ecmaVersion: "latest",
sourceType: "script",
// Self-hosted code defaults to strict mode.
ecmaFeatures: {
impliedStrict: true,
},
// Strict mode has to be enabled separately for the Babel parser.
babelOptions: {
parserOpts: {
strictMode: true,
},
},
},
rules: {
// We should fix those at some point, but we use this to detect NaNs.
@ -114,11 +81,13 @@ module.exports = {
},
{
selector: "VariableDeclaration[kind='let']",
message: "'let' declarations are disallowed to avoid TDZ checks, use 'var' instead",
message:
"'let' declarations are disallowed to avoid TDZ checks, use 'var' instead",
},
{
selector: "VariableDeclaration[kind='const']",
message: "'const' declarations are disallowed to avoid TDZ checks, use 'var' instead",
message:
"'const' declarations are disallowed to avoid TDZ checks, use 'var' instead",
},
],
// Method signatures are important in builtins so disable unused argument errors.
@ -131,7 +100,39 @@ module.exports = {
],
},
languageOptions: {
parserOptions: {
ecmaVersion: "latest",
// Self-hosted code defaults to strict mode.
ecmaFeatures: {
impliedStrict: true,
},
// Strict mode has to be enabled separately for the Babel parser.
babelOptions: {
parserOpts: {
strictMode: true,
},
},
},
sourceType: "script",
globals: {
// Disable all built-in environments.
...mozilla.turnOff(globals.node),
...mozilla.turnOff(globals.browser),
...mozilla.turnOff(globals.builtin),
// We need to explicitly disable the default environments added from
// "tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js".
...mozilla.turnOff(globals.es2021),
...mozilla.turnOff(mozilla.environments.privileged.globals),
...mozilla.turnOff(mozilla.environments.specific.globals),
// Enable SpiderMonkey's self-hosted environment.
...spidermonkeyJS.environments.environment.globals,
// The bytecode compiler special-cases these identifiers.
ArgumentsLength: "readonly",
allowContentIter: "readonly",
@ -173,5 +174,5 @@ module.exports = {
Tuple: "off",
},
},
],
};
},
];

View file

@ -2,19 +2,15 @@
* 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";
import config from "../../toolkit/components/extensions/parent/.eslintrc.mjs";
const {
globals,
} = require("../../toolkit/components/extensions/parent/.eslintrc.js");
module.exports = {
overrides: [
export default [
{
files: ["components/extensions/ext-*.js"],
excludedFiles: ["components/extensions/ext-c-*.js"],
ignores: ["components/extensions/ext-c-*.js"],
languageOptions: {
globals: {
...globals,
...config[0].globals,
// These globals are defined in ext-android.js and can only be used in
// the extension files that run in the parent process.
EventDispatcher: true,
@ -25,6 +21,7 @@ module.exports = {
windowTracker: true,
},
},
},
{
files: [
"chrome/geckoview/**",
@ -69,5 +66,4 @@ module.exports = {
],
},
},
],
};
];

View file

@ -2,9 +2,12 @@
* 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";
import mozilla from "eslint-plugin-mozilla";
export default [
{
plugins: { mozilla },
module.exports = {
rules: {
// Rules from the mozilla plugin
"mozilla/balanced-listeners": "error",
@ -73,4 +76,5 @@ module.exports = {
// Disallow function or variable declarations in nested blocks
"no-inner-declarations": "error",
},
};
},
];

View file

@ -2,10 +2,12 @@
* 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";
import globals from "globals";
module.exports = {
env: {
webextensions: true,
export default [
{
languageOptions: {
globals: globals.webextensions,
},
};
},
];

View file

@ -2,10 +2,12 @@
* 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";
import globals from "globals";
module.exports = {
env: {
webextensions: true,
export default [
{
languageOptions: {
globals: globals.webextensions,
},
};
},
];

View file

@ -2,9 +2,9 @@
* 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";
module.exports = {
export default [
{
languageOptions: {
globals: {
Bookmarks: false,
EnableEngines: false,
@ -12,4 +12,6 @@ module.exports = {
Phase: false,
Sync: false,
},
};
},
},
];

View file

@ -1,14 +1,20 @@
"use strict";
/* 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/. */
module.exports = {
env: {
webextensions: true,
},
import globals from "globals";
export default [
{
languageOptions: {
globals: {
...globals.webextensions,
ExtensionAPI: true,
// available to frameScripts
addMessageListener: false,
content: false,
sendAsyncMessage: false,
},
};
},
},
];

View file

@ -2,10 +2,7 @@
* 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";
module.exports = {
overrides: [
export default [
{
files: [
"chrome/geckoview/**",
@ -50,5 +47,4 @@ module.exports = {
],
},
},
],
};
];

View file

@ -2,28 +2,22 @@
* 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";
import toolkitConfig from "../../../../toolkit/components/extensions/.eslintrc.mjs";
import parentConfig from "../../../../toolkit/components/extensions/parent/.eslintrc.mjs";
import childConfig from "../../../../toolkit/components/extensions/child/.eslintrc.mjs";
const {
globals: globalsParent,
} = require("../../../../toolkit/components/extensions/parent/.eslintrc.js");
const {
globals: globalsChild,
} = require("../../../../toolkit/components/extensions/child/.eslintrc.js");
module.exports = {
extends: "../../../../toolkit/components/extensions/.eslintrc.js",
export default [
...toolkitConfig,
// Ideally mobile should also follow the convention of
// parent/ext-*.js for parent scripts and
// child/ext-*.js for child scripts,
// but the current file structure predates the parent/ vs child/ separation.
overrides: [
{
files: ["ext-*.js"],
excludedFiles: ["ext-c-*.js"],
ignores: ["ext-c-*.js"],
languageOptions: {
globals: {
...globalsParent,
...parentConfig[0].languageOptions.globals,
// These globals are defined in ext-android.js and can only be used in
// the extension files that run in the parent process.
EventDispatcher: true,
@ -34,13 +28,11 @@ module.exports = {
windowTracker: true,
},
},
},
{
files: ["ext-c-*.js"],
globals: {
...globalsChild,
// If there were ever globals exported in ext-c-android.js for common
// use, then they would appear here.
...childConfig[0],
},
},
],
};
];

View file

@ -1,6 +1,7 @@
"use strict";
/* 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/. */
module.exports = {
extends:
"../../../../../../toolkit/components/extensions/test/mochitest/.eslintrc.js",
};
import config from "../../../../../../toolkit/components/extensions/test/mochitest/.eslintrc.mjs";
export default config;

View file

@ -1,6 +1,7 @@
"use strict";
/* 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/. */
module.exports = {
extends:
"../../../../../../toolkit/components/extensions/test/xpcshell/.eslintrc.js",
};
import config from "../../../../../../toolkit/components/extensions/test/xpcshell/.eslintrc.mjs";
export default config;

View file

@ -2,11 +2,16 @@
* 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";
import globals from "globals";
module.exports = {
env: {
browser: true,
node: true,
export default [
{
files: ["**/*.js"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
};
},
},
];

View file

@ -2,13 +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/. */
"use strict";
// inherits from ../../tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
module.exports = {
export default [
{
rules: {
camelcase: ["error", { properties: "never" }],
"no-var": "error",
},
};
},
];

View file

@ -1,7 +1,11 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
rules: {
camelcase: "off",
},
};
},
];

View file

@ -2,9 +2,8 @@
* 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";
module.exports = {
export default [
{
rules: {
// Enforce return statements in callbacks of array methods.
"array-callback-return": "error",
@ -43,4 +42,5 @@ module.exports = {
// Disallow Yoda conditions.
yoda: ["error", "never"],
},
};
},
];

View file

@ -1,8 +1,12 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
rules: {
// Disallow non-top level |var| declarations.
"mozilla/var-only-at-top-level": "error",
},
};
},
];

View file

@ -2,12 +2,14 @@
* 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";
module.exports = {
export default [
{
languageOptions: {
globals: {
// JS files in this folder are commonly xpcshell scripts where |arguments|
// is defined in the global scope.
arguments: false,
},
};
},
},
];

View file

@ -1,6 +1,10 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
languageOptions: {
globals: {
// Injected into tests via tps.sys.mjs
Addons: false,
@ -25,4 +29,6 @@ module.exports = {
Windows: false,
WipeServer: false,
},
};
},
},
];

View file

@ -2,10 +2,10 @@
* 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";
import globals from "globals";
module.exports = {
env: {
node: true,
export default [
{
languageOptions: { globals: globals.node },
},
};
];

View file

@ -2,14 +2,15 @@
* 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";
module.exports = {
export default [
{
languageOptions: {
globals: {
// JS files in this folder are commonly xpcshell scripts where |arguments|
// is defined in the global scope.
arguments: false,
},
},
rules: {
// Enforce return statements in callbacks of array methods.
"array-callback-return": "error",
@ -48,4 +49,5 @@ module.exports = {
// Disallow Yoda conditions.
yoda: ["error", "never"],
},
};
},
];

View file

@ -1,7 +1,13 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
languageOptions: {
globals: {
user_pref: true,
},
};
},
},
];

View file

@ -2,11 +2,15 @@
* 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";
import globals from "globals";
module.exports = {
env: {
browser: true,
node: true,
export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
};
},
},
];

View file

@ -2,23 +2,23 @@
* 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";
module.exports = {
env: {
webextensions: true,
},
import globals from "globals";
import mozilla from "eslint-plugin-mozilla";
export default [
{
languageOptions: {
globals: {
...globals.webextensions,
getTestConfig: false,
startMark: true,
endMark: true,
name: true,
},
plugins: ["mozilla"],
},
plugins: { mozilla },
rules: {
"mozilla/avoid-Date-timing": "error",
},
};
},
];

View file

@ -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/. */
"use strict";
import mozilla from "eslint-plugin-mozilla";
module.exports = {
export default [
{
languageOptions: {
globals: {
Cc: false,
Ci: false,
@ -27,10 +29,11 @@ module.exports = {
TalosParentProfiler: true,
tpRecordTime: true,
},
plugins: ["mozilla"],
},
plugins: { mozilla },
rules: {
"mozilla/avoid-Date-timing": "error",
},
};
},
];

View file

@ -1,7 +1,13 @@
"use strict";
/* 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/. */
module.exports = {
plugins: ["react"],
import mozilla from "eslint-plugin-mozilla";
export default [
{
plugins: { mozilla },
languageOptions: {
globals: {
exports: true,
isWorker: true,
@ -11,6 +17,7 @@ module.exports = {
require: true,
dampWindow: true,
},
},
rules: {
"no-unused-vars": ["error", { argsIgnorePattern: "^_", vars: "all" }],
// These are the rules that have been configured so far to match the
@ -23,4 +30,5 @@ module.exports = {
"mozilla/reject-importGlobalProperties": ["error", "everything"],
"mozilla/var-only-at-top-level": "error",
},
};
},
];

View file

@ -1,5 +1,11 @@
{
"rules": {
"no-undef": "off"
}
}
/* 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/. */
export default [
{
rules: {
"no-undef": "off",
},
},
];

View file

@ -1,5 +1,11 @@
{
"rules": {
"no-undef": "off"
}
}
/* 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/. */
export default [
{
rules: {
"no-undef": "off",
},
},
];

View file

@ -2,23 +2,20 @@
* 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";
import globals from "globals";
import eslintPlugin from "eslint-plugin-eslint-plugin";
module.exports = {
plugins: ["eslint-plugin"],
extends: ["plugin:eslint-plugin/recommended"],
// eslint-plugin-mozilla runs under node, so we need a more restrictive
// environment / parser setup here than the rest of mozilla-central.
env: {
browser: false,
node: true,
},
parser: "espree",
export default [
{
...eslintPlugin.configs["flat/recommended"],
languageOptions: {
globals: globals.node,
parserOptions: {
// This should match with the minimum node version that the ESLint CI
// process uses (check the linux64-node toolchain).
ecmaVersion: 12,
},
},
rules: {
camelcase: ["error", { properties: "never" }],
@ -27,4 +24,16 @@ module.exports = {
"one-var": ["error", "never"],
strict: ["error", "global"],
},
};
},
{
files: ["eslint-plugin-mozilla/scripts/createExports.js"],
languageOptions: {
sourceType: "script",
parserOptions: {
ecmaFeatures: {
globalReturn: true,
},
},
},
},
];

View file

@ -1,8 +1,12 @@
"use strict";
/* 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/. */
module.exports = {
export default [
{
rules: {
// Require object keys to be sorted.
"sort-keys": "error",
},
};
},
];

View file

@ -1,5 +1,3 @@
// Dot file to verify that it works
// without license
"use strict";

View file

@ -2,15 +2,17 @@
* 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";
import globals from "globals";
module.exports = {
env: {
jquery: true,
},
export default [
{
languageOptions: {
globals: {
...globals.jquery,
apply: true,
applyChunks: true,
tasks: true,
},
};
},
},
];

View file

@ -2,17 +2,19 @@
* 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";
import eslintPlugin from "eslint-plugin-eslint-plugin";
import globals from "globals";
module.exports = {
plugins: ["eslint-plugin"],
extends: ["plugin:eslint-plugin/recommended"],
env: {
browser: false,
node: true,
export default [
{
plugins: { "eslint-plugin": eslintPlugin },
...eslintPlugin.configs["flat/recommended"],
languageOptions: {
globals: { ...globals.browser, ...globals.node },
},
rules: {
"no-console": "off",
strict: ["error", "global"],
},
};
},
];