Skip to content
Snippets Groups Projects
Commit 06e59b08 authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1782008 - Move ESLint test paths definitions to a separate file. r=mossop

parent a02d8bb5
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
# - intentionally invalid files
# - build directories and other items that we need to ignore
!.eslintrc.js
!.eslintrc*.js
# Always ignore node_modules.
**/node_modules/
......
/* 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/. */
"use strict";
/* eslint-env node */
// The expressions defined below for test paths are the main path formats we
// prefer to support for tests as they are commonly used across the tree.
// See https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint.html#i-m-adding-tests-how-do-i-set-up-the-right-configuration
// for more information.
const browserTestPaths = ["**/test*/**/browser*/"];
const chromeTestPaths = ["**/test*/chrome/"];
const mochitestTestPaths = [
// Note: we do not want to match testing/mochitest as that would apply
// too many globals for that directory.
"**/test/mochitest/",
"**/tests/mochitest/",
"**/test/mochitests/",
"testing/mochitest/tests/SimpleTest/",
"testing/mochitest/tests/Harness_sanity/",
];
const xpcshellTestPaths = [
"**/test*/unit*/**/",
"**/test*/*/unit*/",
"**/test*/xpcshell/**/",
];
module.exports = {
testPaths: {
browser: [...browserTestPaths],
chrome: [...chromeTestPaths],
mochitest: [...mochitestTestPaths],
xpcshell: [...xpcshellTestPaths],
},
};
......@@ -8,6 +8,7 @@ const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-t
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");
const { testPaths } = require("./.eslintrc-test-paths.js");
const fs = require("fs");
const path = require("path");
......@@ -21,33 +22,6 @@ function removeOverrides(config) {
return config;
}
// The expressions defined below for test paths are the main path formats we
// prefer to support for tests as they are commonly used across the tree.
// See https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint.html#i-m-adding-tests-how-do-i-set-up-the-right-configuration
// for more information.
const xpcshellTestPaths = [
"**/test*/unit*/**/",
"**/test*/*/unit*/",
"**/test*/xpcshell/**/",
// Special case for xpcshell harness.
"testing/xpcshell/example/unit/",
];
const browserTestPaths = ["**/test*/**/browser*/"];
const mochitestTestPaths = [
// Note: we do not want to match testing/mochitest as that would apply
// too many globals for that directory.
"**/test/mochitest/",
"**/tests/mochitest/",
"**/test/mochitests/",
"testing/mochitest/tests/SimpleTest/",
"testing/mochitest/tests/Harness_sanity/",
];
const chromeTestPaths = ["**/test*/chrome/"];
const ignorePatterns = [
...fs
.readFileSync(
......@@ -155,7 +129,7 @@ module.exports = {
},
{
...removeOverrides(xpcshellTestConfig),
files: xpcshellTestPaths.map(path => `${path}**`),
files: testPaths.xpcshell.map(path => `${path}**`),
excludedFiles: "devtools/**",
},
{
......@@ -163,7 +137,7 @@ module.exports = {
// 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.
files: xpcshellTestPaths.map(path => `${path}head*.js`),
files: testPaths.xpcshell.map(path => `${path}head*.js`),
rules: {
"no-unused-vars": [
"error",
......@@ -181,7 +155,7 @@ module.exports = {
// section.
// Bug 1612907: This section should go away once the exclusions are removed
// from the following section.
files: xpcshellTestPaths.map(path => `${path}test*.js`),
files: testPaths.xpcshell.map(path => `${path}test*.js`),
rules: {
// No declaring variables that are never used
"no-unused-vars": [
......@@ -197,7 +171,7 @@ module.exports = {
// This section makes global issues with no-unused-vars be reported as
// errors - except for the excluded lists which are being fixed in the
// dependencies of bug 1612907.
files: xpcshellTestPaths.map(path => `${path}test*.js`),
files: testPaths.xpcshell.map(path => `${path}test*.js`),
excludedFiles: [
// These are suitable as good first bugs, take one or two related lines
// per bug.
......@@ -235,16 +209,16 @@ module.exports = {
},
{
...browserTestConfig,
files: browserTestPaths.map(path => `${path}**`),
files: testPaths.browser.map(path => `${path}**`),
},
{
...removeOverrides(mochitestTestConfig),
files: mochitestTestPaths.map(path => `${path}**`),
files: testPaths.mochitest.map(path => `${path}**`),
excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
},
{
...removeOverrides(chromeTestConfig),
files: chromeTestPaths.map(path => `${path}**`),
files: testPaths.chrome.map(path => `${path}**`),
},
{
env: {
......@@ -254,8 +228,8 @@ module.exports = {
"mozilla/simpletest": true,
},
files: [
...mochitestTestPaths.map(path => `${path}/**/*.js`),
...chromeTestPaths.map(path => `${path}/**/*.js`),
...testPaths.mochitest.map(path => `${path}/**/*.js`),
...testPaths.chrome.map(path => `${path}/**/*.js`),
],
},
{
......
......@@ -7,6 +7,7 @@ eslint:
extensions: ['mjs', 'js', 'jsm', 'jsx', 'html', 'sjs', 'xhtml']
support-files:
- '**/.eslintrc.js'
- '.eslintrc-test-paths.js'
- '.eslintignore'
- 'tools/lint/eslint/**'
# Files that can influence global variables
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment