Bug 1240165 - Expand the eslint rule 'mark-test-function-used' to cover xpcshell tests as well as gecko tests and apply to the whole tree. r?mratcliffe
MozReview-Commit-ID: FlbJ8yzWXlw
--- a/accessible/tests/browser/.eslintrc.js
+++ b/accessible/tests/browser/.eslintrc.js
@@ -46,17 +46,16 @@ module.exports = { // eslint-disable-lin
"waitForEvent": true,
"waitForMultipleEvents": true,
"invokeSetAttribute": true,
"invokeSetStyle": true,
"invokeFocus": true,
"findAccessibleChildByID": true
},
"rules": {
- "mozilla/mark-test-function-used": 1,
"mozilla/no-aArgs": 1,
"mozilla/no-cpows-in-tests": 1,
"mozilla/reject-importGlobalProperties": 1,
"mozilla/var-only-at-top-level": 1,
"block-scoped-var": 2,
"brace-style": [2, "1tbs"],
"camelcase": 2,
--- a/browser/components/migration/tests/unit/test_fx_telemetry.js
+++ b/browser/components/migration/tests/unit/test_fx_telemetry.js
@@ -1,16 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* globals do_get_tempdir */
"use strict";
-/* exported run_test */
function run_test() {
run_next_test();
}
function readFile(file) {
let stream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
stream.init(file, -1, -1, Ci.nsIFileInputStream.CLOSE_ON_EOF);
--- a/browser/components/newtab/tests/xpcshell/test_NewTabPrefsProvider.js
+++ b/browser/components/newtab/tests/xpcshell/test_NewTabPrefsProvider.js
@@ -1,12 +1,11 @@
"use strict";
/* global XPCOMUtils, equal, Preferences, NewTabPrefsProvider, run_next_test */
-/* exported run_test */
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NewTabPrefsProvider",
"resource:///modules/NewTabPrefsProvider.jsm");
--- a/browser/components/newtab/tests/xpcshell/test_NewTabSearchProvider.js
+++ b/browser/components/newtab/tests/xpcshell/test_NewTabSearchProvider.js
@@ -1,12 +1,11 @@
"use strict";
/* global XPCOMUtils, NewTabSearchProvider, run_next_test, ok, equal, do_check_true, do_get_profile, Services */
-/* exported run_test */
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NewTabSearchProvider",
"resource:///modules/NewTabSearchProvider.jsm");
@@ -76,9 +75,8 @@ add_task(function* test_search() {
let expectedEngineName = Services.search.currentEngine.name;
// emitter should fire and return the new engine
let [eventName, actualEngineName] = yield promise;
equal(eventName, "browser-search-engine-modified", `emitter sent the correct event ${eventName}`);
equal(expectedEngineName, actualEngineName, `emitter set the correct engine ${expectedEngineName}`);
NewTabSearchProvider.search.uninit();
});
-
--- a/browser/components/newtab/tests/xpcshell/test_PlacesProvider.js
+++ b/browser/components/newtab/tests/xpcshell/test_PlacesProvider.js
@@ -1,14 +1,13 @@
"use strict";
/* global XPCOMUtils, PlacesUtils, PlacesTestUtils, PlacesProvider, NetUtil */
/* global do_get_profile, run_next_test, add_task */
/* global equal, ok */
-/* exported run_test */
const {
utils: Cu,
interfaces: Ci,
} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
--- a/browser/experiments/test/xpcshell/.eslintrc.js
+++ b/browser/experiments/test/xpcshell/.eslintrc.js
@@ -3,13 +3,13 @@
module.exports = {
"extends": [
"../../../../testing/xpcshell/xpcshell.eslintrc.js"
],
"rules": {
"no-unused-vars": ["error", {
"vars": "all",
- "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS|run_test)$",
+ "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS)$",
"args": "none"
}]
}
};
--- a/browser/extensions/formautofill/.eslintrc.js
+++ b/browser/extensions/formautofill/.eslintrc.js
@@ -8,17 +8,16 @@ module.exports = { // eslint-disable-lin
"dump": true,
"TextDecoder": false,
"TextEncoder": false,
},
"rules": {
// Rules from the mozilla plugin
"mozilla/balanced-listeners": 2,
- "mozilla/mark-test-function-used": 1,
"mozilla/no-aArgs": 1,
"mozilla/no-cpows-in-tests": 1,
"mozilla/var-only-at-top-level": 1,
"valid-jsdoc": [2, {
"prefer": {
"return": "returns",
},
--- a/devtools/.eslintrc.js
+++ b/devtools/.eslintrc.js
@@ -32,17 +32,16 @@ module.exports = {
"WebSocket": true,
"XMLHttpRequest": true,
},
"rules": {
// These are the rules that have been configured so far to match the
// devtools coding style.
// Rules from the mozilla plugin
- "mozilla/mark-test-function-used": 1,
"mozilla/no-aArgs": 1,
"mozilla/no-cpows-in-tests": 2,
"mozilla/no-single-arg-cu-import": 2,
// See bug 1224289.
"mozilla/reject-importGlobalProperties": 2,
// devtools/shared/platform is special; see the README.md in that
// directory for details. We reject requires using explicit
// subdirectories of this directory.
--- a/devtools/.eslintrc.xpcshell.js
+++ b/devtools/.eslintrc.xpcshell.js
@@ -8,14 +8,12 @@ module.exports = {
"camelcase": 0,
// Allow using undefined variables so that tests can refer to functions
// and variables defined in head.js files, without having to maintain a
// list of globals in each .eslintrc file.
// Note that bug 1168340 will eventually help auto-registering globals
// from head.js files.
"no-undef": 0,
"block-scoped-var": 0,
- // Allow run_test to be unused in xpcshell
- "no-unused-vars": [2, { "varsIgnorePattern": "run_test" }],
// Tests can always import anything.
"mozilla/reject-some-requires": 0,
}
};
--- a/testing/mochitest/browser.eslintrc.js
+++ b/testing/mochitest/browser.eslintrc.js
@@ -1,13 +1,14 @@
// Parent config file for all browser-chrome files.
module.exports = {
"rules": {
- "mozilla/import-headjs-globals": 2,
- "mozilla/import-browserjs-globals": 2,
+ "mozilla/import-headjs-globals": 1,
+ "mozilla/import-browserjs-globals": 1,
+ "mozilla/mark-test-function-used": 1,
},
"env": {
"browser": true,
//"node": true
},
// All globals made available in the test environment.
--- a/testing/mochitest/chrome.eslintrc.js
+++ b/testing/mochitest/chrome.eslintrc.js
@@ -1,12 +1,13 @@
// Parent config file for all mochitest files.
module.exports = {
rules: {
"mozilla/import-headjs-globals": 1,
+ "mozilla/mark-test-function-used": 1,
},
"env": {
"browser": true,
},
// All globals made available in the test environment.
"globals": {
--- a/testing/mochitest/mochitest.eslintrc.js
+++ b/testing/mochitest/mochitest.eslintrc.js
@@ -1,12 +1,13 @@
// Parent config file for all mochitest files.
module.exports = {
rules: {
"mozilla/import-headjs-globals": 1,
+ "mozilla/mark-test-function-used": 1,
},
"env": {
"browser": true,
},
// All globals made available in the test environment.
"globals": {
--- a/testing/xpcshell/xpcshell.eslintrc.js
+++ b/testing/xpcshell/xpcshell.eslintrc.js
@@ -1,12 +1,13 @@
// Parent config file for all xpcshell files.
module.exports = {
rules: {
"mozilla/import-headjs-globals": 1,
+ "mozilla/mark-test-function-used": 1,
},
// All globals made available in the test environment.
"globals": {
"add_task": false,
"add_test": false,
"Assert": false,
"deepEqual": false,
--- a/toolkit/components/extensions/.eslintrc.js
+++ b/toolkit/components/extensions/.eslintrc.js
@@ -27,17 +27,16 @@ module.exports = { // eslint-disable-lin
"TabManager": true,
"WindowListManager": true,
"XPCOMUtils": true,
},
"rules": {
// Rules from the mozilla plugin
"mozilla/balanced-listeners": 2,
- "mozilla/mark-test-function-used": 1,
"mozilla/no-aArgs": 1,
"mozilla/no-cpows-in-tests": 1,
"mozilla/var-only-at-top-level": 1,
"valid-jsdoc": [2, {
"prefer": {
"return": "returns",
},
--- a/tools/lint/docs/linters/eslint-plugin-mozilla.rst
+++ b/tools/lint/docs/linters/eslint-plugin-mozilla.rst
@@ -67,18 +67,19 @@ The following patterns are supported:
- ``XPCOMUtils.defineLazyModuleGetter(this, "setNamedTimeout", ...)``
- ``loader.lazyGetter(this, "toolboxStrings"``
- ``XPCOMUtils.defineLazyGetter(this, "clipboardHelper"``
mark-test-function-used
-----------------------
-Simply marks test (the test method) as used. This avoids ESLint telling
-us that the function is never called.
+Simply marks `test` (the test method) or `run_test` as used when in mochitests
+or xpcshell tests respectively. This avoids ESLint telling us that the function
+is never called.
no-aArgs
--------
Checks that function argument names don't start with lowercase 'a' followed by
a capital letter. This is to prevent the use of Hungarian notation whereby the
first letter is a prefix that indicates the type or intended use of a variable.
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/rules/mark-test-function-used.js
@@ -1,11 +1,12 @@
/**
- * @fileoverview Simply marks test (the test method) as used. This avoids ESLint
- * telling us that the function is never called..
+ * @fileoverview Simply marks `test` (the test method) or `run_test` as used when
+ * in mochitests or xpcshell tests respectively. This avoids ESLint telling us
+ * that the function is never called.
*
* 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";
@@ -17,16 +18,20 @@ var helpers = require("../helpers");
module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------
return {
Program: function() {
- if (!helpers.getIsBrowserMochitest(this)) {
+ if (helpers.getIsBrowserMochitest(this)) {
+ context.markVariableAsUsed("test");
return;
}
- context.markVariableAsUsed("test");
+ if (helpers.getIsXpcshellTest(this)) {
+ context.markVariableAsUsed("run_test");
+ return;
+ }
}
};
};