2022-10-06 05:10:16 +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-13 23:43:16 +03:00
|
|
|
"use strict";
|
|
|
|
|
2021-04-05 12:41:39 +03:00
|
|
|
const path = require("path");
|
|
|
|
|
2019-05-20 05:09:54 +03:00
|
|
|
const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
|
|
|
|
const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
|
2023-05-06 12:40:40 +03:00
|
|
|
const fs = require("fs");
|
2019-05-20 05:09:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Some configurations have overrides, which can't be specified within overrides,
|
|
|
|
* so we need to remove them.
|
|
|
|
*/
|
|
|
|
function removeOverrides(config) {
|
2019-08-31 15:56:13 +03:00
|
|
|
config = { ...config };
|
2019-05-20 05:09:54 +03:00
|
|
|
delete config.overrides;
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2023-05-06 12:40:40 +03:00
|
|
|
function readFile(path) {
|
|
|
|
return fs
|
|
|
|
.readFileSync(path, { encoding: "utf-8" })
|
|
|
|
.split("\n")
|
|
|
|
.filter(p => p && !p.startsWith("#"))
|
|
|
|
.map(p => p.replace(/^comm\//, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
const ignorePatterns = [
|
|
|
|
...readFile(path.join(__dirname, "tools", "lint", "ThirdPartyPaths.txt")),
|
|
|
|
...readFile(path.join(__dirname, "tools", "lint", "Generated.txt")),
|
|
|
|
];
|
|
|
|
|
2019-05-20 05:09:54 +03:00
|
|
|
const xpcshellTestPaths = [
|
|
|
|
"**/test*/unit*/",
|
|
|
|
"**/test*/xpcshell/",
|
2019-05-20 20:29:08 +03:00
|
|
|
"chat/**/test*/",
|
2019-05-20 05:09:54 +03:00
|
|
|
];
|
|
|
|
|
2020-08-26 13:22:36 +03:00
|
|
|
const browserTestPaths = [
|
|
|
|
"**/test*/**/browser/",
|
|
|
|
"mail/base/test/performance/",
|
2021-07-21 07:43:35 +03:00
|
|
|
"mail/base/test/webextensions/",
|
|
|
|
"mail/test/static/",
|
2020-08-26 13:22:36 +03:00
|
|
|
];
|
2019-05-20 05:09:54 +03:00
|
|
|
|
2016-10-13 23:43:16 +03:00
|
|
|
module.exports = {
|
2021-04-05 12:41:39 +03:00
|
|
|
parser: "@babel/eslint-parser",
|
2020-05-21 11:15:08 +03:00
|
|
|
parserOptions: {
|
|
|
|
sourceType: "script",
|
|
|
|
babelOptions: {
|
2021-04-05 12:41:39 +03:00
|
|
|
configFile: path.join(__dirname, "..", ".babel-eslint.rc.js"),
|
2020-05-21 11:15:08 +03:00
|
|
|
},
|
|
|
|
},
|
2022-10-06 05:10:16 +03:00
|
|
|
settings: {
|
|
|
|
"import/extensions": [".mjs"],
|
|
|
|
// To avoid bad interactions of the html plugin with the xml preprocessor in
|
|
|
|
// eslint-plugin-mozilla, we turn off processing of the html plugin for .xml
|
|
|
|
// files.
|
|
|
|
"html/xml-extensions": [".xhtml"],
|
|
|
|
},
|
|
|
|
// Ignore eslint configurations in parent directories.
|
2019-08-31 15:56:13 +03:00
|
|
|
root: true,
|
2017-03-13 17:30:50 +03:00
|
|
|
|
2023-05-06 12:40:40 +03:00
|
|
|
ignorePatterns,
|
|
|
|
|
2017-03-13 17:30:50 +03:00
|
|
|
// We would like the same base rules as provided by
|
|
|
|
// mozilla/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
|
2019-08-31 15:56:13 +03:00
|
|
|
extends: ["plugin:mozilla/recommended"],
|
2017-03-13 17:30:50 +03:00
|
|
|
|
2016-06-20 15:22:18 +03:00
|
|
|
// When adding items to this file please check for effects on sub-directories.
|
2022-10-06 05:10:16 +03:00
|
|
|
plugins: ["mozilla", "import"],
|
2017-03-13 17:30:50 +03:00
|
|
|
|
2019-08-31 15:56:13 +03:00
|
|
|
rules: {
|
2020-02-20 01:24:47 +03:00
|
|
|
complexity: ["error", 80],
|
2018-11-29 02:04:40 +03:00
|
|
|
"func-names": ["error", "never"],
|
2019-10-17 11:45:54 +03:00
|
|
|
"mozilla/prefer-boolean-length-check": "off",
|
2018-02-08 12:43:53 +03:00
|
|
|
},
|
|
|
|
|
2019-08-31 15:56:13 +03:00
|
|
|
overrides: [
|
|
|
|
{
|
2022-10-06 05:10:16 +03:00
|
|
|
files: [".eslintrc.js"],
|
2019-08-31 15:56:13 +03:00
|
|
|
env: {
|
|
|
|
node: true,
|
2022-10-06 05:10:16 +03:00
|
|
|
browser: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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",
|
|
|
|
"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://"] },
|
|
|
|
],
|
|
|
|
"import/no-useless-path-segments": "error",
|
2019-08-31 15:56:13 +03:00
|
|
|
},
|
2018-11-02 11:04:58 +03:00
|
|
|
},
|
2022-11-29 00:23:35 +03:00
|
|
|
{
|
|
|
|
files: ["mail/components/storybook/**"],
|
|
|
|
rules: {
|
|
|
|
"import/no-unresolved": "off",
|
|
|
|
},
|
|
|
|
},
|
2019-08-31 15:56:13 +03:00
|
|
|
{
|
|
|
|
...removeOverrides(xpcshellTestConfig),
|
|
|
|
files: xpcshellTestPaths.map(path => `${path}**`),
|
|
|
|
rules: {
|
2019-10-24 12:12:17 +03:00
|
|
|
...xpcshellTestConfig.rules,
|
2019-08-31 15:56:13 +03:00
|
|
|
"func-names": "off",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-11-05 06:48:02 +03:00
|
|
|
// If it is a test head file, we turn off global unused variable checks, as it
|
2019-08-31 15:56:13 +03:00
|
|
|
// 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.
|
2019-11-05 06:48:02 +03:00
|
|
|
files: [
|
|
|
|
...browserTestPaths.map(path => `${path}head*.js`),
|
|
|
|
...xpcshellTestPaths.map(path => `${path}head*.js`),
|
|
|
|
],
|
2019-08-31 15:56:13 +03:00
|
|
|
rules: {
|
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
args: "none",
|
|
|
|
vars: "local",
|
|
|
|
},
|
|
|
|
],
|
2023-09-21 08:40:50 +03:00
|
|
|
// Enforce using `let` only when variables are reassigned.
|
|
|
|
"prefer-const": ["error", { destructuring: "all" }],
|
2019-08-31 15:56:13 +03:00
|
|
|
},
|
2019-05-20 05:09:54 +03:00
|
|
|
},
|
2019-08-31 15:56:13 +03:00
|
|
|
{
|
|
|
|
...browserTestConfig,
|
2022-10-06 05:10:16 +03:00
|
|
|
files: browserTestPaths.map(path => `${path}**`),
|
2019-09-27 07:00:10 +03:00
|
|
|
rules: {
|
2019-10-24 12:12:17 +03:00
|
|
|
...browserTestConfig.rules,
|
2019-09-27 07:00:10 +03:00
|
|
|
"func-names": "off",
|
|
|
|
},
|
2019-05-20 05:09:54 +03:00
|
|
|
},
|
2019-08-31 15:56:13 +03:00
|
|
|
],
|
2016-10-13 23:43:16 +03:00
|
|
|
};
|