Commit 53b3788b authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1415265 - Implement a central configuration for setting ESLint...

Bug 1415265 - Implement a central configuration for setting ESLint environments for test directories. r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D23849

--HG--
extra : moz-landing-system : lando
parent 38c5f252
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
"use strict";

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");

/**
 * Some configurations have overrides, which can't be specified within overrides,
 * so we need to remove them.
 */
function removeOverrides(config) {
  config = {...config};
  delete config.overrides;
  return config;
}

const xpcshellTestPaths = [
  "**/test*/unit*/",
  "**/test*/xpcshell/",
];

const browserTestPaths = [
  "**/test*/**/browser/",
];

const mochitestTestPaths = [
  "**/test*/mochitest/",
];

const chromeTestPaths = [
  "**/test*/chrome/",
];

module.exports = {
  // New rules and configurations should generally be added in
  // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
@@ -84,5 +116,51 @@ module.exports = {
    "rules": {
      "no-throw-literal": "off",
    }
  }, {
    ...removeOverrides(xpcshellTestConfig),
    "files": xpcshellTestPaths.map(path => `${path}**`),
    "excludedFiles": "devtools/**"
  }, {
    // 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.
    "files": xpcshellTestPaths.map(path => `${path}head*.js`),

    "rules": {
      "no-unused-vars": ["error", {
        "args": "none",
        "vars": "local",
      }],
    },
  }, {
    ...browserTestConfig,
    "files": browserTestPaths.map(path => `${path}**`),
    "excludedFiles": "devtools/**"
  }, {
    ...removeOverrides(mochitestTestConfig),
    "files": mochitestTestPaths.map(path => `${path}**`),
    "excludedFiles": [
      "devtools/**",
      "security/manager/ssl/tests/mochitest/browser/**",
      "testing/mochitest/**",
    ],
  }, {
    ...removeOverrides(chromeTestConfig),
    "files": chromeTestPaths.map(path => `${path}**`),
    "excludedFiles": [
      "devtools/**",
    ],
  }, {
    "env": {
      // Ideally we wouldn't be using the simpletest env here, but our uses of
      // 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,
    },
    "files": [
      ...mochitestTestPaths.map(path => `${path}/**/*.js`),
      ...chromeTestPaths.map(path => `${path}/**/*.js`),
    ],
  }]
};
+0 −3
Original line number Diff line number Diff line
"use strict";

module.exports = {
  "extends": [
    "plugin:mozilla/browser-test"
  ],
  "rules": {
    "mozilla/no-aArgs": "error",
    "mozilla/reject-importGlobalProperties": ["error", "everything"],
+0 −3
Original line number Diff line number Diff line
"use strict";

module.exports = {
  "extends": [
    "plugin:mozilla/mochitest-test"
  ],
  "rules": {
    // XXX These are rules that are enabled in the recommended configuration, but
    // disabled here due to failures when initially implemented. They should be
+0 −2
Original line number Diff line number Diff line
"use strict";

module.exports = {
  "extends": "plugin:mozilla/browser-test",

  "env": {
    "webextensions": true,
  },
+0 −2
Original line number Diff line number Diff line
"use strict";

module.exports = {
  "extends": "plugin:mozilla/xpcshell-test",

  "env": {
    // The tests in this folder are testing based on WebExtensions, so lets
    // just define the webextensions environment here.
Loading