Bug 1331006 - [eslint] Define more globals, and add a rule to import test globals from SimpleTest/EventUtils. r=mossop

MozReview-Commit-ID: 5ifWLAa8wG2

--HG--
extra : rebase_source : a5698cb08548a547faf9a9379cacaca428b67c00
This commit is contained in:
Mark Banner 2017-01-12 10:24:10 +00:00
Родитель 9846692940
Коммит 8be1b0f008
12 изменённых файлов: 92 добавлений и 14 удалений

Просмотреть файл

@ -3,6 +3,7 @@ module.exports = {
"rules": { "rules": {
"mozilla/import-headjs-globals": "warn", "mozilla/import-headjs-globals": "warn",
"mozilla/import-browserjs-globals": "warn", "mozilla/import-browserjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn", "mozilla/mark-test-function-used": "warn",
}, },
@ -13,6 +14,8 @@ module.exports = {
// All globals made available in the test environment. // All globals made available in the test environment.
"globals": { "globals": {
// `$` is defined in SimpleTest.js
"$": false,
"add_task": false, "add_task": false,
"addLoadEvent": false, "addLoadEvent": false,
"Assert": false, "Assert": false,
@ -38,7 +41,6 @@ module.exports = {
"privateNoteIntentionalCrash": false, "privateNoteIntentionalCrash": false,
"registerCleanupFunction": false, "registerCleanupFunction": false,
"requestLongerTimeout": false, "requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false, "SpecialPowers": false,
"TestUtils": false, "TestUtils": false,
"thisTestLeaksUncaughtRejectionsAndShouldBeFixed": false, "thisTestLeaksUncaughtRejectionsAndShouldBeFixed": false,

Просмотреть файл

@ -2,6 +2,7 @@
module.exports = { module.exports = {
rules: { rules: {
"mozilla/import-headjs-globals": "warn", "mozilla/import-headjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn", "mozilla/mark-test-function-used": "warn",
}, },
@ -11,6 +12,8 @@ module.exports = {
// All globals made available in the test environment. // All globals made available in the test environment.
"globals": { "globals": {
// `$` is defined in SimpleTest.js
"$": false,
"add_task": false, "add_task": false,
"addLoadEvent": false, "addLoadEvent": false,
"Assert": false, "Assert": false,
@ -29,7 +32,6 @@ module.exports = {
"promise": false, "promise": false,
"registerCleanupFunction": false, "registerCleanupFunction": false,
"requestLongerTimeout": false, "requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false, "SpecialPowers": false,
"todo": false, "todo": false,
"todo_is": false, "todo_is": false,

Просмотреть файл

@ -2,6 +2,7 @@
module.exports = { module.exports = {
rules: { rules: {
"mozilla/import-headjs-globals": "warn", "mozilla/import-headjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn", "mozilla/mark-test-function-used": "warn",
"no-shadow": "error", "no-shadow": "error",
}, },
@ -12,7 +13,7 @@ module.exports = {
// All globals made available in the test environment. // All globals made available in the test environment.
"globals": { "globals": {
// $ is defined in SimpleTest.js // `$` is defined in SimpleTest.js
"$": false, "$": false,
"add_task": false, "add_task": false,
"addLoadEvent": false, "addLoadEvent": false,
@ -33,7 +34,6 @@ module.exports = {
"promise": false, "promise": false,
"registerCleanupFunction": false, "registerCleanupFunction": false,
"requestLongerTimeout": false, "requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false, "SpecialPowers": false,
"todo": false, "todo": false,
"todo_is": false, "todo_is": false,

Просмотреть файл

@ -249,7 +249,14 @@ module.exports = {
"dump": true, "dump": true,
"KeyEvent": false, "KeyEvent": false,
"openDialog": false, "openDialog": false,
"MenuBoxObject": false,
"sizeToContent": false, "sizeToContent": false,
"SharedArrayBuffer": 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
} }
}; };

Просмотреть файл

@ -0,0 +1,7 @@
"use strict";
module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../testing/mochitest/mochitest.eslintrc.js",
]
};

Просмотреть файл

@ -14,7 +14,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
<p id="display">This is the text to search i<b>n&shy;t</b>o</p> <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> <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 id="content" style="display: none">
</div> </div>
<pre id="test"> <pre id="test">
<script type="application/javascript"> <script type="application/javascript">
@ -144,19 +144,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
rf.caseSensitive = false; rf.caseSensitive = false;
rf.findBackwards = false; rf.findBackwards = false;
function find(node, searchValue) { function find(node, value) {
var range = document.createRange(); var range = document.createRange();
range.setStart(node, 0); range.setStart(node, 0);
range.setEnd(node, node.childNodes.length); range.setEnd(node, node.childNodes.length);
return rf.Find(searchValue, range, range, range); return rf.Find(value, range, range, range);
} }
function assertFound(node, searchValue) { function assertFound(node, value) {
ok(find(node, searchValue), "\"" + searchValue + "\" not found"); ok(find(node, value), "\"" + value + "\" not found");
} }
function assertNotFound(node, searchValue) { function assertNotFound(node, value) {
ok(!find(node, searchValue), "\"" + searchValue + "\" found"); ok(!find(node, value), "\"" + value + "\" found");
} }
var quotes = document.getElementById("quotes"); var quotes = document.getElementById("quotes");

Просмотреть файл

@ -0,0 +1,7 @@
"use strict";
module.exports = { // eslint-disable-line no-undef
"extends": [
"../../../../../testing/xpcshell/xpcshell.eslintrc.js",
]
};

Просмотреть файл

@ -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",
]
};

Просмотреть файл

@ -10,6 +10,7 @@ var Cr = Components.results;
function loadUtilsScript() { function loadUtilsScript() {
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader); getService(Ci.mozIJSSubScriptLoader);
/* import-globals-from ../../contentAreaUtils.js */
loader.loadSubScript("chrome://global/content/contentAreaUtils.js"); loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
} }

Просмотреть файл

@ -18,9 +18,10 @@ module.exports = {
}, },
rules: { rules: {
"balanced-listeners": require("../lib/rules/balanced-listeners"), "balanced-listeners": require("../lib/rules/balanced-listeners"),
"import-browserjs-globals": require("../lib/rules/import-browserjs-globals"),
"import-globals": require("../lib/rules/import-globals"), "import-globals": require("../lib/rules/import-globals"),
"import-headjs-globals": require("../lib/rules/import-headjs-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"), "mark-test-function-used": require("../lib/rules/mark-test-function-used"),
"no-aArgs": require("../lib/rules/no-aArgs"), "no-aArgs": require("../lib/rules/no-aArgs"),
"no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"), "no-cpows-in-tests": require("../lib/rules/no-cpows-in-tests"),
@ -33,9 +34,10 @@ module.exports = {
}, },
rulesConfig: { rulesConfig: {
"balanced-listeners": 0, "balanced-listeners": 0,
"import-browserjs-globals": 0,
"import-globals": 0, "import-globals": 0,
"import-headjs-globals": 0, "import-headjs-globals": 0,
"import-browserjs-globals": 0, "import-test-globals": 0,
"mark-test-function-used": 0, "mark-test-function-used": 0,
"no-aArgs": 0, "no-aArgs": 0,
"no-cpows-in-tests": 0, "no-cpows-in-tests": 0,

Просмотреть файл

@ -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());
}
}
};
};

Просмотреть файл

@ -1,6 +1,6 @@
{ {
"name": "eslint-plugin-mozilla", "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.", "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [ "keywords": [
"eslint", "eslint",