Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1331006 - [eslint] Define more globals, and add a rule to import …
Browse files Browse the repository at this point in the history
…test globals from SimpleTest/EventUtils. r=mossop

MozReview-Commit-ID: 5ifWLAa8wG2
  • Loading branch information
Standard8 committed Jan 12, 2017
1 parent 23a86b1 commit db213f9
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 14 deletions.
4 changes: 3 additions & 1 deletion testing/mochitest/browser.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
"rules": {
"mozilla/import-headjs-globals": "warn",
"mozilla/import-browserjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn",
},

Expand All @@ -13,6 +14,8 @@ module.exports = {

// All globals made available in the test environment.
"globals": {
// `$` is defined in SimpleTest.js
"$": false,
"add_task": false,
"addLoadEvent": false,
"Assert": false,
Expand All @@ -38,7 +41,6 @@ module.exports = {
"privateNoteIntentionalCrash": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"TestUtils": false,
"thisTestLeaksUncaughtRejectionsAndShouldBeFixed": false,
Expand Down
4 changes: 3 additions & 1 deletion testing/mochitest/chrome.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
rules: {
"mozilla/import-headjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn",
},

Expand All @@ -11,6 +12,8 @@ module.exports = {

// All globals made available in the test environment.
"globals": {
// `$` is defined in SimpleTest.js
"$": false,
"add_task": false,
"addLoadEvent": false,
"Assert": false,
Expand All @@ -29,7 +32,6 @@ module.exports = {
"promise": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"todo": false,
"todo_is": false,
Expand Down
4 changes: 2 additions & 2 deletions testing/mochitest/mochitest.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
rules: {
"mozilla/import-headjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn",
"no-shadow": "error",
},
Expand All @@ -12,7 +13,7 @@ module.exports = {

// All globals made available in the test environment.
"globals": {
// $ is defined in SimpleTest.js
// `$` is defined in SimpleTest.js
"$": false,
"add_task": false,
"addLoadEvent": false,
Expand All @@ -33,7 +34,6 @@ module.exports = {
"promise": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"todo": false,
"todo_is": false,
Expand Down
7 changes: 7 additions & 0 deletions toolkit/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ module.exports = {
"dump": true,
"KeyEvent": false,
"openDialog": false,
"MenuBoxObject": false,
"sizeToContent": false,
"SharedArrayBuffer": false,
// Note: StopIteration will likely be removed as part of removing legacy
// generators, see bug 968038.
"StopIteration": false,
// Specific to Firefox
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval
"uneval": false
}
};
7 changes: 7 additions & 0 deletions toolkit/components/windowcreator/test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../testing/mochitest/mochitest.eslintrc.js",
]
};
14 changes: 7 additions & 7 deletions toolkit/components/windowcreator/test/test_nsFind.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<p id="display">This is the text to search i<b>n&shy;t</b>o</p>
<p id="quotes">"straight" and &ldquo;curly&rdquo; and &lsquo;didn't&rsquo; and 'doesn&rsquo;t'</p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
Expand Down Expand Up @@ -144,19 +144,19 @@
rf.caseSensitive = false;
rf.findBackwards = false;

function find(node, searchValue) {
function find(node, value) {
var range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, node.childNodes.length);
return rf.Find(searchValue, range, range, range);
return rf.Find(value, range, range, range);
}

function assertFound(node, searchValue) {
ok(find(node, searchValue), "\"" + searchValue + "\" not found");
function assertFound(node, value) {
ok(find(node, value), "\"" + value + "\" not found");
}

function assertNotFound(node, searchValue) {
ok(!find(node, searchValue), "\"" + searchValue + "\" found");
function assertNotFound(node, value) {
ok(!find(node, value), "\"" + value + "\" found");
}

var quotes = document.getElementById("quotes");
Expand Down
7 changes: 7 additions & 0 deletions toolkit/components/windowcreator/tests/unit/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../../testing/xpcshell/xpcshell.eslintrc.js",
]
};
9 changes: 9 additions & 0 deletions toolkit/components/windowwatcher/test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../testing/mochitest/browser.eslintrc.js",
"../../../../testing/mochitest/chrome.eslintrc.js",
"../../../../testing/mochitest/mochitest.eslintrc.js",
]
};
1 change: 1 addition & 0 deletions toolkit/content/tests/unit/test_contentAreaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Cr = Components.results;
function loadUtilsScript() {
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
/* import-globals-from ../../contentAreaUtils.js */
loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
}

Expand Down
6 changes: 4 additions & 2 deletions tools/lint/eslint/eslint-plugin-mozilla/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ module.exports = {
},
rules: {
"balanced-listeners": require("../lib/rules/balanced-listeners"),
"import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
"import-globals": require("../lib/rules/import-globals"),
"import-headjs-globals": require("../lib/rules/import-headjs-globals"),
"import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
"import-test-globals": require("../lib/rules/import-test-globals"),
"mark-test-function-used": require("../lib/rules/mark-test-function-used"),
"no-aArgs": require("../lib/rules/no-aArgs"),
"no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
Expand All @@ -33,9 +34,10 @@ module.exports = {
},
rulesConfig: {
"balanced-listeners": 0,
"import-browserjs-globals": 0,
"import-globals": 0,
"import-headjs-globals": 0,
"import-browserjs-globals": 0,
"import-test-globals": 0,
"mark-test-function-used": 0,
"no-aArgs": 0,
"no-cpows-in-tests": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @fileoverview Import globals from common mochitest files, so that we
* don't need to specify them individually.
*
* 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";

// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------

var fs = require("fs");
var path = require("path");
var helpers = require("../helpers");
var globals = require("../globals");

const simpleTestFiles = [
"EventUtils.js",
"SimpleTest.js"
];
const simpleTestPath = "testing/mochitest/tests/SimpleTest";

module.exports = function(context) {
// ---------------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------------

return {
Program: function(node) {
for (let file of simpleTestFiles) {
let newGlobals =
globals.getGlobalsForFile(path.join(simpleTestPath, file));
helpers.addGlobals(newGlobals, context.getScope());
}
}
};
};
2 changes: 1 addition & 1 deletion tools/lint/eslint/eslint-plugin-mozilla/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "0.2.10",
"version": "0.2.11",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",
Expand Down

0 comments on commit db213f9

Please sign in to comment.