2020-03-18 12:27:54 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2016-10-18 10:38:10 +03:00
|
|
|
"use strict";
|
|
|
|
|
2019-03-28 12:38:02 +03:00
|
|
|
const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
|
|
|
|
const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
|
|
|
|
const mochitestTestConfig = require("eslint-plugin-mozilla/lib/configs/mochitest-test.js");
|
|
|
|
const chromeTestConfig = require("eslint-plugin-mozilla/lib/configs/chrome-test.js");
|
2024-07-16 15:53:09 +03:00
|
|
|
const globalIgnores = require("./.eslintrc-ignores.js");
|
2022-08-03 14:16:19 +03:00
|
|
|
const { testPaths } = require("./.eslintrc-test-paths.js");
|
2024-05-21 16:38:01 +03:00
|
|
|
const { rollouts } = require("./.eslintrc-rollouts.js");
|
2020-01-21 23:46:06 +03:00
|
|
|
const fs = require("fs");
|
2020-01-25 00:55:04 +03:00
|
|
|
const path = require("path");
|
2019-03-28 12:38:02 +03:00
|
|
|
|
2024-09-13 00:08:44 +03:00
|
|
|
function readFile(filePath) {
|
2022-09-09 21:46:38 +03:00
|
|
|
return fs
|
2024-09-13 00:08:44 +03:00
|
|
|
.readFileSync(filePath, { encoding: "utf-8" })
|
2022-09-09 21:46:38 +03:00
|
|
|
.split("\n")
|
|
|
|
.filter(p => p && !p.startsWith("#"));
|
|
|
|
}
|
|
|
|
|
2020-01-21 23:46:38 +03:00
|
|
|
const ignorePatterns = [
|
2024-07-16 15:53:09 +03:00
|
|
|
...globalIgnores,
|
2022-09-09 21:46:38 +03:00
|
|
|
...readFile(
|
|
|
|
path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
|
|
|
|
),
|
|
|
|
...readFile(path.join(__dirname, "tools", "rewriting", "Generated.txt")),
|
|
|
|
...readFile(
|
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
"devtools",
|
|
|
|
"client",
|
|
|
|
"debugger",
|
|
|
|
"src",
|
|
|
|
".eslintignore"
|
2020-01-25 00:55:04 +03:00
|
|
|
)
|
2022-09-09 21:46:38 +03:00
|
|
|
).map(p => `devtools/client/debugger/src/${p}`),
|
2020-01-21 23:46:38 +03:00
|
|
|
];
|
2022-09-07 11:45:12 +03:00
|
|
|
const httpTestingPaths = [
|
|
|
|
"**/*mixedcontent",
|
|
|
|
"**/*CrossOrigin",
|
|
|
|
"**/*crossorigin",
|
|
|
|
"**/*cors",
|
|
|
|
"**/*downgrade",
|
|
|
|
"**/*Downgrade",
|
|
|
|
];
|
2020-01-21 23:46:06 +03:00
|
|
|
|
2016-10-18 10:38:10 +03:00
|
|
|
module.exports = {
|
2022-06-09 16:02:15 +03:00
|
|
|
settings: {
|
|
|
|
"import/extensions": [".mjs"],
|
|
|
|
},
|
2020-01-21 23:46:06 +03:00
|
|
|
ignorePatterns,
|
2020-01-24 17:56:09 +03:00
|
|
|
// Ignore eslint configurations in parent directories.
|
|
|
|
root: true,
|
2024-10-18 12:21:27 +03:00
|
|
|
env: {
|
|
|
|
es2024: true,
|
|
|
|
},
|
2017-04-25 22:12:21 +03:00
|
|
|
// New rules and configurations should generally be added in
|
|
|
|
// tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
|
|
|
|
// allow external repositories that use the plugin to pick them up as well.
|
2024-09-23 20:46:18 +03:00
|
|
|
extends: [
|
|
|
|
"plugin:mozilla/recommended",
|
2024-09-25 09:37:10 +03:00
|
|
|
"plugin:json/recommended-with-comments-legacy",
|
2024-09-23 20:46:18 +03:00
|
|
|
"prettier",
|
|
|
|
],
|
|
|
|
plugins: ["mozilla", "html", "import", "json"],
|
2017-10-09 12:54:16 +03:00
|
|
|
overrides: [
|
2024-10-18 12:21:27 +03:00
|
|
|
{
|
|
|
|
files: ["*.*"],
|
|
|
|
// The browser environment is not available for system modules, sjs, workers
|
|
|
|
// or any of the xpcshell-test files.
|
|
|
|
excludedFiles: [
|
|
|
|
"*.sys.mjs",
|
|
|
|
"*.sjs",
|
|
|
|
"**/?(*.)worker.?(m)js",
|
|
|
|
...testPaths.xpcshell.map(filePath => `${filePath}**`),
|
|
|
|
],
|
|
|
|
env: {
|
|
|
|
browser: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ["*.*"],
|
|
|
|
env: {
|
|
|
|
"mozilla/privileged": true,
|
|
|
|
"mozilla/specific": true,
|
|
|
|
},
|
2024-11-01 17:15:01 +03:00
|
|
|
rules: {
|
|
|
|
// Require braces around blocks that start a new line. This must be
|
|
|
|
// configured after eslint-config-prettier is included (via `extends`
|
|
|
|
// above), as otherwise that configuration disables it. Hence, we do
|
|
|
|
// not include it in
|
|
|
|
// `tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js`.
|
|
|
|
curly: ["error", "all"],
|
|
|
|
},
|
2024-10-18 12:21:27 +03:00
|
|
|
},
|
2020-03-07 12:30:44 +03:00
|
|
|
{
|
2024-02-07 11:55:29 +03:00
|
|
|
files: [
|
|
|
|
// All .eslintrc.js files are in the node environment, so turn that
|
|
|
|
// on here.
|
|
|
|
// https://github.com/eslint/eslint/issues/13008
|
2024-05-21 16:38:01 +03:00
|
|
|
".eslintrc*.js",
|
2024-02-07 11:55:29 +03:00
|
|
|
// *.config.js files are generally assumed to be configuration files
|
|
|
|
// based for node.
|
|
|
|
"*.config.?(m)js",
|
|
|
|
],
|
2020-03-07 12:30:44 +03:00
|
|
|
env: {
|
|
|
|
node: true,
|
|
|
|
browser: false,
|
|
|
|
},
|
|
|
|
},
|
2024-05-21 16:38:01 +03:00
|
|
|
{
|
|
|
|
files: ["browser/base/content/browser.js"],
|
|
|
|
rules: {
|
|
|
|
"mozilla/no-more-globals": "error",
|
|
|
|
},
|
|
|
|
},
|
2024-02-02 21:45:08 +03:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"**/*.jsx",
|
|
|
|
"browser/components/pocket/content/**/*.js",
|
|
|
|
"browser/components/storybook/.storybook/**/*.mjs",
|
|
|
|
],
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-14 12:13:49 +03:00
|
|
|
{
|
|
|
|
files: ["browser/components/storybook/**"],
|
|
|
|
env: {
|
|
|
|
"mozilla/privileged": false,
|
|
|
|
},
|
|
|
|
},
|
2017-10-09 12:54:16 +03:00
|
|
|
{
|
2022-06-09 16:02:15 +03:00
|
|
|
files: ["*.mjs"],
|
|
|
|
rules: {
|
|
|
|
"import/default": "error",
|
|
|
|
"import/export": "error",
|
|
|
|
"import/named": "error",
|
|
|
|
"import/namespace": "error",
|
|
|
|
"import/newline-after-import": "error",
|
|
|
|
"import/no-duplicates": "error",
|
|
|
|
"import/no-absolute-path": "error",
|
|
|
|
"import/no-named-default": "error",
|
|
|
|
"import/no-named-as-default": "error",
|
|
|
|
"import/no-named-as-default-member": "error",
|
|
|
|
"import/no-self-import": "error",
|
|
|
|
"import/no-unassigned-import": "error",
|
2022-07-29 11:10:05 +03:00
|
|
|
"import/no-unresolved": [
|
|
|
|
"error",
|
|
|
|
// Bug 1773473 - Ignore resolver URLs for chrome and resource as we
|
|
|
|
// do not yet have a resolver for them.
|
|
|
|
{ ignore: ["chrome://", "resource://"] },
|
|
|
|
],
|
2022-06-09 16:02:15 +03:00
|
|
|
"import/no-useless-path-segments": "error",
|
|
|
|
},
|
|
|
|
},
|
2024-05-15 19:08:57 +03:00
|
|
|
{
|
|
|
|
// Turn off no-unassigned-import for files that typically test our
|
|
|
|
// custom elements, which are imported for the side effects (ie
|
|
|
|
// the custom element being registered) rather than any particular
|
|
|
|
// export:
|
|
|
|
files: ["**/*.stories.mjs"],
|
|
|
|
rules: {
|
|
|
|
"import/no-unassigned-import": "off",
|
|
|
|
},
|
|
|
|
},
|
2024-05-20 16:49:44 +03:00
|
|
|
{
|
|
|
|
files: ["**/test/**", "**/tests/**"],
|
|
|
|
extends: ["plugin:mozilla/general-test"],
|
|
|
|
},
|
2020-03-07 13:09:44 +03:00
|
|
|
{
|
2024-09-13 00:08:45 +03:00
|
|
|
...xpcshellTestConfig,
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}**`),
|
2024-05-20 16:49:44 +03:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
{
|
2019-09-04 19:33:11 +03:00
|
|
|
// If it is an xpcshell head file, we turn off global unused variable checks, as it
|
|
|
|
// would require searching the other test files to know if they are used or not.
|
|
|
|
// This would be expensive and slow, and it isn't worth it for head files.
|
|
|
|
// We could get developers to declare as exported, but that doesn't seem worth it.
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}head*.js`),
|
2020-03-07 13:09:44 +03:00
|
|
|
rules: {
|
2019-09-04 19:33:11 +03:00
|
|
|
"no-unused-vars": [
|
2020-03-07 13:09:44 +03:00
|
|
|
"error",
|
|
|
|
{
|
Bug 1864896: Enable unused argument lint rule. r=Standard8,perftest-reviewers,geckoview-reviewers,extension-reviewers,credential-management-reviewers,devtools-reviewers,nchevobbe,robwu,sparky,issammani,sgalich,owlish,migration-reviewers,mconley
Differential Revision: https://phabricator.services.mozilla.com/D195632
2024-03-21 11:50:00 +03:00
|
|
|
argsIgnorePattern: "^_",
|
2019-03-28 12:38:02 +03:00
|
|
|
vars: "local",
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 14:07:02 +03:00
|
|
|
{
|
2022-10-03 19:30:03 +03:00
|
|
|
// This section enables errors of no-unused-vars globally for all test*.js
|
2021-10-11 14:07:02 +03:00
|
|
|
// files in xpcshell test paths.
|
2022-10-03 19:30:03 +03:00
|
|
|
// This is not done in the xpcshell-test configuration as we cannot pull
|
|
|
|
// in overrides from there. We should at some stage, aim to enable this
|
|
|
|
// for all files in xpcshell-tests.
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}test*.js`),
|
2021-10-11 14:07:02 +03:00
|
|
|
rules: {
|
|
|
|
// No declaring variables that are never used
|
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{
|
Bug 1864896: Enable unused argument lint rule. r=Standard8,perftest-reviewers,geckoview-reviewers,extension-reviewers,credential-management-reviewers,devtools-reviewers,nchevobbe,robwu,sparky,issammani,sgalich,owlish,migration-reviewers,mconley
Differential Revision: https://phabricator.services.mozilla.com/D195632
2024-03-21 11:50:00 +03:00
|
|
|
argsIgnorePattern: "^_",
|
2021-10-11 14:07:02 +03:00
|
|
|
vars: "all",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-03-07 13:09:44 +03:00
|
|
|
{
|
2024-09-13 00:08:45 +03:00
|
|
|
...browserTestConfig,
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.browser.map(filePath => `${filePath}**`),
|
2024-05-20 16:49:44 +03:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
{
|
2024-09-13 00:08:45 +03:00
|
|
|
...mochitestTestConfig,
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.mochitest.map(filePath => `${filePath}**`),
|
2023-02-13 15:26:46 +03:00
|
|
|
excludedFiles: [
|
|
|
|
"**/*.jsm",
|
|
|
|
"**/*.mjs",
|
|
|
|
"security/manager/ssl/tests/mochitest/browser/**",
|
|
|
|
],
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
{
|
2024-09-13 00:08:45 +03:00
|
|
|
...chromeTestConfig,
|
2024-09-13 00:08:44 +03:00
|
|
|
files: testPaths.chrome.map(filePath => `${filePath}**`),
|
2024-05-20 16:49:44 +03:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
{
|
2019-09-04 19:33:11 +03:00
|
|
|
env: {
|
2019-03-28 12:38:02 +03:00
|
|
|
// Ideally we wouldn't be using the simpletest env here, but our uses of
|
2019-09-04 19:33:11 +03:00
|
|
|
// js files mean we pick up everything from the global scope, which could
|
|
|
|
// be any one of a number of html files. So we just allow the basics...
|
|
|
|
"mozilla/simpletest": true,
|
2020-03-07 13:09:44 +03:00
|
|
|
},
|
|
|
|
files: [
|
2024-09-13 00:08:44 +03:00
|
|
|
...testPaths.mochitest.map(filePath => `${filePath}/**/*.js`),
|
|
|
|
...testPaths.chrome.map(filePath => `${filePath}/**/*.js`),
|
2020-03-07 13:09:44 +03:00
|
|
|
],
|
2024-05-20 16:49:44 +03:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2019-09-04 19:33:11 +03:00
|
|
|
},
|
2024-02-20 15:40:07 +03:00
|
|
|
{
|
|
|
|
// Some directories have multiple kinds of tests, and some rules
|
|
|
|
// don't work well for HTML-based mochitests, so disable those.
|
|
|
|
files: testPaths.xpcshell
|
|
|
|
.concat(testPaths.browser)
|
2024-09-13 00:08:44 +03:00
|
|
|
.map(filePath => [`${filePath}/**/*.html`, `${filePath}/**/*.xhtml`])
|
2024-02-20 15:40:07 +03:00
|
|
|
.flat(),
|
|
|
|
rules: {
|
|
|
|
// plain/chrome mochitests don't automatically include Assert, so
|
|
|
|
// autofixing `ok()` to Assert.something is bad.
|
|
|
|
"mozilla/no-comparison-or-assignment-inside-ok": "off",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Some directories reuse `test_foo.js` files between mochitest-plain and
|
|
|
|
// unit tests, or use custom postMessage-based assertion propagation into
|
|
|
|
// browser tests. Ignore those too:
|
|
|
|
files: [
|
|
|
|
// Reuses xpcshell unit test scripts in mochitest-plain HTML files.
|
|
|
|
"dom/indexedDB/test/**",
|
|
|
|
// Dispatches functions to the webpage in ways that are hard to detect.
|
|
|
|
"toolkit/components/antitracking/test/**",
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
"mozilla/no-comparison-or-assignment-inside-ok": "off",
|
|
|
|
},
|
|
|
|
},
|
2022-03-25 21:01:21 +03:00
|
|
|
{
|
|
|
|
// Rules of Hooks broadly checks for camelCase "use" identifiers, so
|
|
|
|
// enable only for paths actually using React to avoid false positives.
|
|
|
|
extends: ["plugin:react-hooks/recommended"],
|
|
|
|
files: [
|
2023-12-11 21:02:41 +03:00
|
|
|
"browser/components/aboutwelcome/**",
|
2023-12-14 21:46:55 +03:00
|
|
|
"browser/components/asrouter/**",
|
2022-03-25 21:01:21 +03:00
|
|
|
"browser/components/newtab/**",
|
|
|
|
"browser/components/pocket/**",
|
|
|
|
"devtools/**",
|
|
|
|
],
|
2023-09-05 15:43:35 +03:00
|
|
|
rules: {
|
|
|
|
// react-hooks/recommended has exhaustive-deps as a warning, we prefer
|
|
|
|
// errors, so that raised issues get addressed one way or the other.
|
|
|
|
"react-hooks/exhaustive-deps": "error",
|
|
|
|
},
|
2022-03-25 21:01:21 +03:00
|
|
|
},
|
2022-09-07 11:45:12 +03:00
|
|
|
{
|
|
|
|
// Exempt files with these paths since they have to use http for full coverage
|
2024-09-13 00:08:44 +03:00
|
|
|
files: httpTestingPaths.map(filePath => `${filePath}**`),
|
2022-09-07 11:45:12 +03:00
|
|
|
rules: {
|
|
|
|
"@microsoft/sdl/no-insecure-url": "off",
|
|
|
|
},
|
|
|
|
},
|
2024-07-03 14:41:30 +03:00
|
|
|
// JSM Handling. This handles the obsolete JSM files whilst we await the
|
|
|
|
// removal of JSM. These reflect some of the rules in recommended.js but
|
|
|
|
// are moved here to simplify reworking the configuration for flat config.
|
|
|
|
{
|
|
|
|
// System mjs files and jsm 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: {
|
|
|
|
browser: false,
|
|
|
|
"mozilla/sysmjs": true,
|
|
|
|
},
|
|
|
|
files: ["**/*.jsm"],
|
|
|
|
rules: {
|
|
|
|
"mozilla/lazy-getter-object-name": "error",
|
|
|
|
"mozilla/mark-exported-symbols-as-used": "error",
|
|
|
|
"mozilla/reject-eager-module-in-lazy-getter": "error",
|
|
|
|
"mozilla/reject-global-this": "error",
|
|
|
|
"mozilla/reject-globalThis-modification": "error",
|
|
|
|
// For all system modules, we expect no properties to need importing,
|
|
|
|
// hence reject everything.
|
|
|
|
"mozilla/reject-importGlobalProperties": ["error", "everything"],
|
|
|
|
"mozilla/reject-mixing-eager-and-lazy": "error",
|
|
|
|
"mozilla/reject-top-level-await": "error",
|
|
|
|
// Modules and workers are far easier to check for no-unused-vars on a
|
|
|
|
// global scope, than our content files. Hence we turn that on here.
|
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
argsIgnorePattern: "^_",
|
|
|
|
vars: "all",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2024-05-21 16:38:01 +03:00
|
|
|
...rollouts,
|
2020-03-07 13:09:44 +03:00
|
|
|
],
|
2016-10-18 10:38:10 +03:00
|
|
|
};
|