2020-03-18 09:27:54 +00: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 07:38:10 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-03-28 09:38:02 +00: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 12:53:09 +00:00
|
|
|
const globalIgnores = require("./.eslintrc-ignores.js");
|
2022-08-03 11:16:19 +00:00
|
|
|
const { testPaths } = require("./.eslintrc-test-paths.js");
|
2024-05-21 13:38:01 +00:00
|
|
|
const { rollouts } = require("./.eslintrc-rollouts.js");
|
2020-01-21 20:46:06 +00:00
|
|
|
const fs = require("fs");
|
2020-01-24 21:55:04 +00:00
|
|
|
const path = require("path");
|
2019-03-28 09:38:02 +00:00
|
|
|
|
2024-09-12 21:08:44 +00:00
|
|
|
function readFile(filePath) {
|
2022-09-09 18:46:38 +00:00
|
|
|
return fs
|
2024-09-12 21:08:44 +00:00
|
|
|
.readFileSync(filePath, { encoding: "utf-8" })
|
2022-09-09 18:46:38 +00:00
|
|
|
.split("\n")
|
|
|
|
.filter(p => p && !p.startsWith("#"));
|
|
|
|
}
|
|
|
|
|
2020-01-21 20:46:38 +00:00
|
|
|
const ignorePatterns = [
|
2024-07-16 12:53:09 +00:00
|
|
|
...globalIgnores,
|
2022-09-09 18:46:38 +00: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-24 21:55:04 +00:00
|
|
|
)
|
2022-09-09 18:46:38 +00:00
|
|
|
).map(p => `devtools/client/debugger/src/${p}`),
|
2020-01-21 20:46:38 +00:00
|
|
|
];
|
2022-09-07 08:45:12 +00:00
|
|
|
const httpTestingPaths = [
|
|
|
|
"**/*mixedcontent",
|
|
|
|
"**/*CrossOrigin",
|
|
|
|
"**/*crossorigin",
|
|
|
|
"**/*cors",
|
|
|
|
"**/*downgrade",
|
|
|
|
"**/*Downgrade",
|
|
|
|
];
|
2020-01-21 20:46:06 +00:00
|
|
|
|
2016-10-18 07:38:10 +00:00
|
|
|
module.exports = {
|
2022-06-09 13:02:15 +00:00
|
|
|
settings: {
|
|
|
|
"import/extensions": [".mjs"],
|
|
|
|
},
|
2020-01-21 20:46:06 +00:00
|
|
|
ignorePatterns,
|
2020-01-24 14:56:09 +00:00
|
|
|
// Ignore eslint configurations in parent directories.
|
|
|
|
root: true,
|
2017-04-25 19:12:21 +00: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 17:46:18 +00:00
|
|
|
extends: [
|
|
|
|
"plugin:mozilla/recommended",
|
2024-09-25 06:37:10 +00:00
|
|
|
"plugin:json/recommended-with-comments-legacy",
|
2024-09-23 17:46:18 +00:00
|
|
|
"prettier",
|
|
|
|
],
|
|
|
|
plugins: ["mozilla", "html", "import", "json"],
|
2017-10-09 09:54:16 +00:00
|
|
|
overrides: [
|
2020-03-07 09:30:44 +00:00
|
|
|
{
|
2024-02-07 08:55:29 +00: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 13:38:01 +00:00
|
|
|
".eslintrc*.js",
|
2024-02-07 08:55:29 +00:00
|
|
|
// *.config.js files are generally assumed to be configuration files
|
|
|
|
// based for node.
|
|
|
|
"*.config.?(m)js",
|
|
|
|
],
|
2020-03-07 09:30:44 +00:00
|
|
|
env: {
|
|
|
|
node: true,
|
|
|
|
browser: false,
|
|
|
|
},
|
|
|
|
},
|
2024-05-21 13:38:01 +00:00
|
|
|
{
|
|
|
|
files: ["browser/base/content/browser.js"],
|
|
|
|
rules: {
|
|
|
|
"mozilla/no-more-globals": "error",
|
|
|
|
},
|
|
|
|
},
|
2024-02-02 18:45:08 +00:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"**/*.jsx",
|
|
|
|
"browser/components/pocket/content/**/*.js",
|
|
|
|
"browser/components/storybook/.storybook/**/*.mjs",
|
|
|
|
],
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-14 09:13:49 +00:00
|
|
|
{
|
|
|
|
files: ["browser/components/storybook/**"],
|
|
|
|
env: {
|
|
|
|
"mozilla/privileged": false,
|
|
|
|
},
|
|
|
|
},
|
2017-10-09 09:54:16 +00:00
|
|
|
{
|
2022-06-09 13:02:15 +00: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 08:10:05 +00: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 13:02:15 +00:00
|
|
|
"import/no-useless-path-segments": "error",
|
|
|
|
},
|
|
|
|
},
|
2024-05-15 16:08:57 +00: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 13:49:44 +00:00
|
|
|
{
|
|
|
|
files: ["**/test/**", "**/tests/**"],
|
|
|
|
extends: ["plugin:mozilla/general-test"],
|
|
|
|
},
|
2020-03-07 10:09:44 +00:00
|
|
|
{
|
2024-09-12 21:08:45 +00:00
|
|
|
...xpcshellTestConfig,
|
2024-09-12 21:08:44 +00:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}**`),
|
2024-05-20 13:49:44 +00:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 10:09:44 +00:00
|
|
|
},
|
|
|
|
{
|
2019-09-04 16:33:11 +00: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-12 21:08:44 +00:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}head*.js`),
|
2020-03-07 10:09:44 +00:00
|
|
|
rules: {
|
2019-09-04 16:33:11 +00:00
|
|
|
"no-unused-vars": [
|
2020-03-07 10:09:44 +00: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 08:50:00 +00:00
|
|
|
argsIgnorePattern: "^_",
|
2019-03-28 09:38:02 +00:00
|
|
|
vars: "local",
|
2020-03-07 10:09:44 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 11:07:02 +00:00
|
|
|
{
|
2022-10-03 16:30:03 +00:00
|
|
|
// This section enables errors of no-unused-vars globally for all test*.js
|
2021-10-11 11:07:02 +00:00
|
|
|
// files in xpcshell test paths.
|
2022-10-03 16:30:03 +00: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-12 21:08:44 +00:00
|
|
|
files: testPaths.xpcshell.map(filePath => `${filePath}test*.js`),
|
2021-10-11 11:07:02 +00: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 08:50:00 +00:00
|
|
|
argsIgnorePattern: "^_",
|
2021-10-11 11:07:02 +00:00
|
|
|
vars: "all",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2020-03-07 10:09:44 +00:00
|
|
|
{
|
2024-09-12 21:08:45 +00:00
|
|
|
...browserTestConfig,
|
2024-09-12 21:08:44 +00:00
|
|
|
files: testPaths.browser.map(filePath => `${filePath}**`),
|
2024-05-20 13:49:44 +00:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 10:09:44 +00:00
|
|
|
},
|
|
|
|
{
|
2024-09-12 21:08:45 +00:00
|
|
|
...mochitestTestConfig,
|
2024-09-12 21:08:44 +00:00
|
|
|
files: testPaths.mochitest.map(filePath => `${filePath}**`),
|
2023-02-13 12:26:46 +00:00
|
|
|
excludedFiles: [
|
|
|
|
"**/*.jsm",
|
|
|
|
"**/*.mjs",
|
|
|
|
"security/manager/ssl/tests/mochitest/browser/**",
|
|
|
|
],
|
2020-03-07 10:09:44 +00:00
|
|
|
},
|
|
|
|
{
|
2024-09-12 21:08:45 +00:00
|
|
|
...chromeTestConfig,
|
2024-09-12 21:08:44 +00:00
|
|
|
files: testPaths.chrome.map(filePath => `${filePath}**`),
|
2024-05-20 13:49:44 +00:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2020-03-07 10:09:44 +00:00
|
|
|
},
|
|
|
|
{
|
2019-09-04 16:33:11 +00:00
|
|
|
env: {
|
2019-03-28 09:38:02 +00:00
|
|
|
// Ideally we wouldn't be using the simpletest env here, but our uses of
|
2019-09-04 16:33:11 +00: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 10:09:44 +00:00
|
|
|
},
|
|
|
|
files: [
|
2024-09-12 21:08:44 +00:00
|
|
|
...testPaths.mochitest.map(filePath => `${filePath}/**/*.js`),
|
|
|
|
...testPaths.chrome.map(filePath => `${filePath}/**/*.js`),
|
2020-03-07 10:09:44 +00:00
|
|
|
],
|
2024-05-20 13:49:44 +00:00
|
|
|
excludedFiles: ["**/*.jsm", "**/*.mjs", "**/*.sjs"],
|
2019-09-04 16:33:11 +00:00
|
|
|
},
|
2024-02-20 12:40:07 +00: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-12 21:08:44 +00:00
|
|
|
.map(filePath => [`${filePath}/**/*.html`, `${filePath}/**/*.xhtml`])
|
2024-02-20 12:40:07 +00: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 18:01:21 +00: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 18:02:41 +00:00
|
|
|
"browser/components/aboutwelcome/**",
|
2023-12-14 18:46:55 +00:00
|
|
|
"browser/components/asrouter/**",
|
2022-03-25 18:01:21 +00:00
|
|
|
"browser/components/newtab/**",
|
|
|
|
"browser/components/pocket/**",
|
|
|
|
"devtools/**",
|
|
|
|
],
|
2023-09-05 12:43:35 +00: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 18:01:21 +00:00
|
|
|
},
|
2022-09-07 08:45:12 +00:00
|
|
|
{
|
|
|
|
// Exempt files with these paths since they have to use http for full coverage
|
2024-09-12 21:08:44 +00:00
|
|
|
files: httpTestingPaths.map(filePath => `${filePath}**`),
|
2022-09-07 08:45:12 +00:00
|
|
|
rules: {
|
|
|
|
"@microsoft/sdl/no-insecure-url": "off",
|
|
|
|
},
|
|
|
|
},
|
2024-07-03 11:41:30 +00: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 13:38:01 +00:00
|
|
|
...rollouts,
|
2020-03-07 10:09:44 +00:00
|
|
|
],
|
2016-10-18 07:38:10 +00:00
|
|
|
};
|