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": {
"mozilla/import-headjs-globals": "warn",
"mozilla/import-browserjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn",
},
@ -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,
@ -38,7 +41,6 @@ module.exports = {
"privateNoteIntentionalCrash": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"TestUtils": false,
"thisTestLeaksUncaughtRejectionsAndShouldBeFixed": false,

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

@ -2,6 +2,7 @@
module.exports = {
rules: {
"mozilla/import-headjs-globals": "warn",
"mozilla/import-test-globals": "warn",
"mozilla/mark-test-function-used": "warn",
},
@ -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,
@ -29,7 +32,6 @@ module.exports = {
"promise": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"todo": false,
"todo_is": false,

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

@ -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",
},
@ -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,
@ -33,7 +34,6 @@ module.exports = {
"promise": false,
"registerCleanupFunction": false,
"requestLongerTimeout": false,
"SimpleTest": false,
"SpecialPowers": false,
"todo": false,
"todo_is": false,

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

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

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

@ -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="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">
@ -144,19 +144,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=450048
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");

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

@ -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() {
var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
/* import-globals-from ../../contentAreaUtils.js */
loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
}

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

@ -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"),
@ -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,

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

@ -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",
"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",