Bug 1375678 - Enable lint on testing/modules - mechanical changes; r=standard8

This commit is contained in:
Geoff Brown 2017-06-23 15:08:02 -06:00
Родитель dd80ef173b
Коммит 03ec89d132
13 изменённых файлов: 110 добавлений и 94 удалений

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

@ -300,7 +300,9 @@ services/sync/services-sync.js
# testing/ exclusions
testing/marionette/**
testing/mochitest/**
testing/modules/**
# third party modules
testing/modules/ajv-4.1.1.js
testing/modules/sinon-2.3.2.js
# octothorpe used for pref file comment causes parsing error
testing/mozbase/mozprofile/tests/files/prefs_with_comments.js
testing/talos/**

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

@ -29,7 +29,7 @@ var gFakeAppDirectoryProvider;
* This returns a promise that will be resolved once the new directory
* is created and installed.
*/
this.makeFakeAppDir = function () {
this.makeFakeAppDir = function() {
let dirMode = OS.Constants.libc.S_IRWXU;
let dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
@ -65,7 +65,7 @@ this.makeFakeAppDir = function () {
makeDir(submittedD);
let provider = {
getFile: function (prop, persistent) {
getFile(prop, persistent) {
persistent.value = true;
if (prop == "UAppData") {
return appD.clone();
@ -74,7 +74,7 @@ this.makeFakeAppDir = function () {
throw Cr.NS_ERROR_FAILURE;
},
QueryInterace: function (iid) {
QueryInterace(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
@ -91,7 +91,7 @@ this.makeFakeAppDir = function () {
// And undefine the old one.
try {
dirService.undefine("UAppData");
} catch (ex) {};
} catch (ex) {}
gFakeAppDirectoryProvider = provider;

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

@ -31,7 +31,7 @@ let origPlatformInfo = Cc["@mozilla.org/xre/app-info;1"]
* crashReporter: nsICrashReporter interface is implemented if true
* extraProps: extra properties added to XULAppInfo
*/
this.newAppInfo = function (options={}) {
this.newAppInfo = function(options = {}) {
let ID = ("ID" in options) ? options.ID : "xpcshell@tests.mozilla.org";
let name = ("name" in options) ? options.name : "xpcshell";
let version = ("version" in options) ? options.version : "1";
@ -43,19 +43,19 @@ this.newAppInfo = function (options={}) {
let appInfo = {
// nsIXULAppInfo
vendor: "Mozilla",
name: name,
ID: ID,
version: version,
name,
ID,
version,
appBuildID: "20160315",
// nsIPlatformInfo
platformVersion: platformVersion,
platformVersion,
platformBuildID: origPlatformInfo.platformBuildID,
// nsIXULRuntime
inSafeMode: false,
logConsoleErrors: true,
OS: OS,
OS,
XPCOMABI: "noarch-spidermonkey",
invalidateCachesOnRestart() {},
@ -95,7 +95,7 @@ var currentAppInfo = newAppInfo();
/**
* Obtain a reference to the current object used to define XULAppInfo.
*/
this.getAppInfo = function () { return currentAppInfo; };
this.getAppInfo = function() { return currentAppInfo; };
/**
* Update the current application info.
@ -105,7 +105,7 @@ this.getAppInfo = function () { return currentAppInfo; };
* To change the current XULAppInfo, simply call this function. If there was
* a previously registered app info object, it will be unloaded and replaced.
*/
this.updateAppInfo = function (options) {
this.updateAppInfo = function(options) {
currentAppInfo = newAppInfo(options);
let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
@ -119,7 +119,7 @@ this.updateAppInfo = function (options) {
} catch (ex) {}
let factory = {
createInstance: function (outer, iid) {
createInstance(outer, iid) {
if (outer != null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}

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

@ -56,9 +56,9 @@ const kTruncateLength = 128;
function truncate(text, newLength = kTruncateLength) {
if (typeof text == "string") {
return text.length < newLength ? text : text.slice(0, newLength);
} else {
return text;
}
return text;
}
function getMessage(error, prefix = "") {
@ -109,7 +109,7 @@ Assert.AssertionError = function(options) {
let stack = Components.stack;
do {
stack = stack.asyncCaller || stack.caller;
} while(stack && stack.filename && stack.filename.includes("Assert.jsm"))
} while (stack && stack.filename && stack.filename.includes("Assert.jsm"))
this.stack = stack;
};
@ -181,10 +181,10 @@ proto.setReporter = function(reporterFunc) {
*/
proto.report = function(failed, actual, expected, message, operator) {
let err = new Assert.AssertionError({
message: message,
actual: actual,
expected: expected,
operator: operator
message,
actual,
expected,
operator
});
if (!this._reporter) {
// If no custom reporter is set, throw the error.

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

@ -19,7 +19,7 @@ addDebuggerToGlobal(this);
/**
* Records coverage for each test by way of the js debugger.
*/
this.CoverageCollector = function (prefix) {
this.CoverageCollector = function(prefix) {
this._prefix = prefix;
this._dbg = new Debugger();
this._dbg.collectCoverageInfo = true;
@ -37,7 +37,7 @@ this.CoverageCollector = function (prefix) {
this._testIndex = 0;
}
CoverageCollector.prototype._getLinesCovered = function () {
CoverageCollector.prototype._getLinesCovered = function() {
let coveredLines = {};
let currentCoverage = {};
this._scripts.forEach(s => {
@ -60,7 +60,7 @@ CoverageCollector.prototype._getLinesCovered = function () {
this._allCoverage[scriptName] = {};
}
let key = [lineNumber, columnNumber, offset].join('#');
let key = [lineNumber, columnNumber, offset].join("#");
if (!currentCoverage[scriptName][key]) {
currentCoverage[scriptName][key] = count;
} else {
@ -80,7 +80,7 @@ CoverageCollector.prototype._getLinesCovered = function () {
!this._allCoverage[scriptName][key] ||
(this._allCoverage[scriptName][key] <
currentCoverage[scriptName][key])) {
let [lineNumber, colNumber, offset] = key.split('#');
let [lineNumber, colNumber, offset] = key.split("#");
if (!coveredLines[scriptName]) {
coveredLines[scriptName] = new Set();
}
@ -115,7 +115,7 @@ CoverageCollector.prototype._getUncoveredLines = function() {
// For all covered lines, delete their entry
for (let scriptName in this._allCoverage) {
for (let key in this._allCoverage[scriptName]) {
let [lineNumber, columnNumber, offset] = key.split('#');
let [lineNumber, columnNumber, offset] = key.split("#");
uncoveredLines[scriptName].delete(parseInt(lineNumber, 10));
}
}
@ -145,7 +145,7 @@ CoverageCollector.prototype._getMethodNames = function() {
* push a record of the form:
* <method name> : <lines covered>
*/
scriptOffsets.forEach( function (element, index) {
scriptOffsets.forEach( function(element, index) {
if (!element) {
return;
}
@ -174,7 +174,7 @@ Object.prototype[Symbol.iterator] = function * () {
* associating them with the given test name. The result is written
* to a json file in a specified directory.
*/
CoverageCollector.prototype.recordTestCoverage = function (testName) {
CoverageCollector.prototype.recordTestCoverage = function(testName) {
let ccov_scope = {};
const {OS} = Cu.import("resource://gre/modules/osfile.jsm", ccov_scope);
@ -195,7 +195,7 @@ CoverageCollector.prototype.recordTestCoverage = function (testName) {
uncovered: []
};
if (typeof(methods[scriptName]) != 'undefined' && methods[scriptName] != null) {
if (typeof(methods[scriptName]) != "undefined" && methods[scriptName] != null) {
for (let [methodName, methodLines] of methods[scriptName]) {
rec.methods[methodName] = methodLines;
}
@ -212,15 +212,15 @@ CoverageCollector.prototype.recordTestCoverage = function (testName) {
result.push(rec);
}
let arr = this._encoder.encode(JSON.stringify(result, null, 2));
let path = this._prefix + '/' + 'jscov_' + Date.now() + '.json';
let path = this._prefix + "/" + "jscov_" + Date.now() + ".json";
dump("Writing coverage to: " + path + "\n");
return OS.File.writeAtomic(path, arr, {tmpPath: path + '.tmp'});
return OS.File.writeAtomic(path, arr, {tmpPath: path + ".tmp"});
}
/**
* Tear down the debugger after all tests are complete.
*/
CoverageCollector.prototype.finalize = function () {
CoverageCollector.prototype.finalize = function() {
this._dbg.removeAllDebuggees();
this._dbg.enabled = false;
}

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

@ -62,7 +62,7 @@ this.MockRegistrar = Object.freeze({
try {
let genuine = originalFactory.createInstance(outer, iid);
wrappedMock._genuine = genuine;
} catch(ex) {
} catch (ex) {
logger.info("Creating original instance failed", ex);
}
@ -81,9 +81,9 @@ this.MockRegistrar = Object.freeze({
factory);
this._registeredComponents.set(originalCID, {
contractID: contractID,
factory: factory,
originalFactory: originalFactory
contractID,
factory,
originalFactory
});
return originalCID;

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

@ -38,7 +38,7 @@ class MockRegistry {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowsRegKey]),
// --- Overridden nsIWindowsRegKey interface functions ---
open: function(root, path, mode) {
open(root, path, mode) {
let rootKey = registry.getRoot(root);
if (!rootKey.has(path)) {
rootKey.set(path, new Map());
@ -46,7 +46,7 @@ class MockRegistry {
this.values = rootKey.get(path);
},
close: function() {
close() {
this.values = null;
},
@ -56,25 +56,25 @@ class MockRegistry {
return this.values.size;
},
hasValue: function(name) {
hasValue(name) {
if (!this.values) {
return false;
}
return this.values.has(name);
},
getValueType: function(name) {
getValueType(name) {
return Ci.nsIWindowsRegKey.TYPE_STRING;
},
getValueName: function(index) {
getValueName(index) {
if (!this.values || index >= this.values.size)
throw Components.results.NS_ERROR_FAILURE;
let names = Array.from(this.values.keys());
return names[index];
},
readStringValue: function(name) {
readStringValue(name) {
if (!this.values) {
throw new Error("invalid registry path");
}
@ -111,5 +111,5 @@ class MockRegistry {
pathmap.set(name, value);
}
}
};
}

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

@ -23,7 +23,7 @@ this.EXPORTED_SYMBOLS = [
* These will each be called with the complete object to log as an
* argument.
*/
this.StructuredLogger = function(name, dumpFun=dump, mutators=[]) {
this.StructuredLogger = function(name, dumpFun = dump, mutators = []) {
this.name = name;
this._dumpFun = dumpFun;
this._mutatorFuns = mutators;
@ -33,13 +33,13 @@ this.StructuredLogger = function(name, dumpFun=dump, mutators=[]) {
* Log functions producing messages in the format specified by mozlog
*/
StructuredLogger.prototype = {
testStart: function (test) {
testStart(test) {
var data = {test: this._testId(test)};
this._logData("test_start", data);
},
testStatus: function (test, subtest, status, expected="PASS",
message=null, stack=null, extra=null) {
testStatus(test, subtest, status, expected = "PASS",
message = null, stack = null, extra = null) {
if (subtest === null || subtest === undefined) {
// Fix for assertions that don't pass in a name
@ -48,8 +48,8 @@ StructuredLogger.prototype = {
var data = {
test: this._testId(test),
subtest: subtest,
status: status,
subtest,
status,
};
if (expected != status && status != "SKIP") {
@ -68,8 +68,8 @@ StructuredLogger.prototype = {
this._logData("test_status", data);
},
testEnd: function (test, status, expected="OK", message=null, stack=null, extra=null) {
var data = {test: this._testId(test), status: status};
testEnd(test, status, expected = "OK", message = null, stack = null, extra = null) {
var data = {test: this._testId(test), status};
if (expected != status && status != "SKIP") {
data.expected = expected;
@ -87,16 +87,16 @@ StructuredLogger.prototype = {
this._logData("test_end", data);
},
assertionCount: function (test, count, minExpected=0, maxExpected=0) {
var data = {test: test,
assertionCount(test, count, minExpected = 0, maxExpected = 0) {
var data = {test,
min_expected: minExpected,
max_expected: maxExpected,
count: count};
count};
this._logData("assertion_count", data);
},
suiteStart: function (tests, runinfo=null, versioninfo=null, deviceinfo=null, extra=null) {
suiteStart(tests, runinfo = null, versioninfo = null, deviceinfo = null, extra = null) {
var data = {tests: tests.map(x => this._testId(x))};
if (runinfo !== null) {
data.runinfo = runinfo;
@ -117,7 +117,7 @@ StructuredLogger.prototype = {
this._logData("suite_start", data);
},
suiteEnd: function (extra=null) {
suiteEnd(extra = null) {
var data = {};
if (extra !== null) {
@ -133,9 +133,9 @@ StructuredLogger.prototype = {
* log suite specific data. If a "stack" field is provided it is logged at the
* top level of the data object for the benefit of mozlog's formatters.
*/
log: function (level, message, extra=null) {
log(level, message, extra = null) {
var data = {
level: level,
level,
message: String(message),
};
@ -149,37 +149,37 @@ StructuredLogger.prototype = {
this._logData("log", data);
},
debug: function (message, extra=null) {
debug(message, extra = null) {
this.log("DEBUG", message, extra);
},
info: function (message, extra=null) {
info(message, extra = null) {
this.log("INFO", message, extra);
},
warning: function (message, extra=null) {
warning(message, extra = null) {
this.log("WARNING", message, extra);
},
error: function (message, extra=null) {
error(message, extra = null) {
this.log("ERROR", message, extra);
},
critical: function (message, extra=null) {
critical(message, extra = null) {
this.log("CRITICAL", message, extra);
},
processOutput: function(thread, message) {
this._logData('process_output', {
message: message,
thread: thread,
processOutput(thread, message) {
this._logData("process_output", {
message,
thread,
});
},
_logData: function (action, data={}) {
_logData(action, data = {}) {
var allData = {
action: action,
action,
time: Date.now(),
thread: null,
pid: null,
@ -197,7 +197,7 @@ StructuredLogger.prototype = {
this._dumpFun(allData);
},
_testId: function(test) {
_testId(test) {
if (Array.isArray(test)) {
return test.join(" ");
}
@ -216,32 +216,32 @@ this.StructuredFormatter = function() {
StructuredFormatter.prototype = {
log: function(message) {
log(message) {
return message.message;
},
suite_start: function(message) {
suite_start(message) {
this.suiteStartTime = message.time;
return "SUITE-START | Running " + message.tests.length + " tests";
return "SUITE-START | Running " + message.tests.length + " tests";
},
test_start: function(message) {
test_start(message) {
this.testStartTimes[message.test] = new Date().getTime();
return "TEST-START | " + message.test;
},
test_status: function(message) {
test_status(message) {
var statusInfo = message.test + " | " + message.subtest +
(message.message ? " | " + message.message : "");
if (message.expected) {
return "TEST-UNEXPECTED-" + message.status + " | " + statusInfo +
" - expected: " + message.expected;
} else {
return "TEST-" + message.status + " | " + statusInfo;
}
return "TEST-" + message.status + " | " + statusInfo;
},
test_end: function(message) {
test_end(message) {
var startTime = this.testStartTimes[message.test];
delete this.testStartTimes[message.test];
var statusInfo = message.test + (message.message ? " | " + String(message.message) : "");
@ -255,7 +255,7 @@ StructuredFormatter.prototype = {
result = " | took " + message.time - startTime + "ms";
},
suite_end: function(message) {
suite_end(message) {
return "SUITE-END | took " + message.time - this.suiteStartTime + "ms";
}
};

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

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/browser-test"
]
};

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

@ -0,0 +1,7 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/xpcshell-test"
]
};

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

@ -31,7 +31,7 @@ function run_test() {
let clsChain = protoCtrChain(cls.prototype);
let objChain = protoCtrChain(obj);
return objChain.slice(-clsChain.length) === clsChain;
};
}
assert.ok(indirectInstanceOf(ns.Assert.AssertionError.prototype, Error),
"Assert.AssertionError instanceof Error");
@ -118,7 +118,7 @@ function run_test() {
assert.deepEqual(a1, a2);
let nbRoot = {
toString: function() { return this.first + " " + this.last; }
toString() { return this.first + " " + this.last; }
};
function nameBuilder(first, last) {
@ -246,7 +246,7 @@ function run_test() {
// https://github.com/joyent/node/issues/2893
try {
assert.throws(function () {
assert.throws(function() {
ifError(null);
});
} catch (e) {
@ -278,7 +278,7 @@ function run_test() {
// Test robustness of reporting:
equal(new ns.Assert.AssertionError({
actual: {
toJSON: function() {
toJSON() {
throw "bam!";
}
},
@ -290,7 +290,7 @@ function run_test() {
assert.greater(3, 2);
try {
assert.greater(2, 2);
} catch(e) {
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 2 > 2");
@ -298,7 +298,7 @@ function run_test() {
assert.greaterOrEqual(2, 2);
try {
assert.greaterOrEqual(1, 2);
} catch(e) {
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 1 >= 2");
@ -306,7 +306,7 @@ function run_test() {
assert.less(1, 2);
try {
assert.less(2, 2);
} catch(e) {
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 2 < 2");
@ -314,7 +314,7 @@ function run_test() {
assert.lessOrEqual(2, 2);
try {
assert.lessOrEqual(2, 1);
} catch(e) {
} catch (e) {
message = e.toString().split("\n")[0];
}
assert.equal(message, "AssertionError: 2 <= 1");
@ -332,7 +332,7 @@ add_task(async function test_rejects() {
try {
await assert.rejects(Promise.reject(err), expected);
ok(false, "should have thrown");
} catch(ex) {
} catch (ex) {
deepEqual(ex, err, "Assert.rejects threw the original unexpected error");
}
}

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

@ -17,7 +17,7 @@ userInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIUserInfo]),
};
function run_test () {
function run_test() {
run_next_test();
}

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

@ -1,16 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test () {
function run_test() {
Components.utils.import("resource://testing-common/StructuredLog.jsm");
let testBuffer = [];
let appendBuffer = function (msg) {
let appendBuffer = function(msg) {
testBuffer.push(JSON.stringify(msg));
}
let assertLastMsg = function (refData) {
let assertLastMsg = function(refData) {
// Check all fields in refData agree with those in the
// last message logged, and pop that message.
let lastMsg = JSON.parse(testBuffer.pop());
@ -23,7 +23,7 @@ function run_test () {
equal(lastMsg.source_file, "test_structuredlog.js");
}
let addFileName = function (data) {
let addFileName = function(data) {
data.source_file = "test_structuredlog.js";
}
@ -38,7 +38,7 @@ function run_test () {
});
logger.info("Test message",
extra={foo: "bar"});
extra = {foo: "bar"});
assertLastMsg({
action: "log",
message: "Test message",