Skip to content

Commit

Permalink
Run prettier on all files and fix violations
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Oct 8, 2018
1 parent 5730481 commit 6f48865
Show file tree
Hide file tree
Showing 69 changed files with 5,506 additions and 4,122 deletions.
18 changes: 8 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ var pkg = require("./package.json");
var date = new Date().toISOString().split("T")[0];

// Keep the preamble on one line to retain source maps
var preamble = "/* Sinon.JS " + pkg.version + ", " + date
+ ", @license BSD-3 */";
var preamble = "/* Sinon.JS " + pkg.version + ", " + date + ", @license BSD-3 */";

try {
fs.mkdirSync("pkg");
Expand All @@ -23,15 +22,14 @@ function makeBundle(name, config) {
// Create a UMD wrapper and install the "sinon" global:
config.standalone = "sinon";

browserify("./lib/sinon.js", config)
.bundle(function (err, buffer) {
if (err) {
throw err;
}
browserify("./lib/sinon.js", config).bundle(function(err, buffer) {
if (err) {
throw err;
}

var script = preamble + buffer.toString();
fs.writeFileSync("pkg/" + name + ".js", script);
});
var script = preamble + buffer.toString();
fs.writeFileSync("pkg/" + name + ".js", script);
});
}

makeBundle("sinon", {
Expand Down
23 changes: 11 additions & 12 deletions eslint-local-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function getPrototypeMethods(prototype) {
/* eslint-disable local-rules/no-prototype-methods */
return Object.getOwnPropertyNames(prototype).filter(function (name) {
return Object.getOwnPropertyNames(prototype).filter(function(name) {
return typeof prototype[name] === "function" && prototype.hasOwnProperty(name);
});
}
Expand All @@ -25,19 +25,19 @@ module.exports = {
schema: []
},

create: function (context) {
create: function(context) {
/**
* Reports if a disallowed property is used in a CallExpression
* @param {ASTNode} node The CallExpression node.
* @returns {void}
*/
* Reports if a disallowed property is used in a CallExpression
* @param {ASTNode} node The CallExpression node.
* @returns {void}
*/
function disallowBuiltIns(node) {
if (
node.callee.type !== "MemberExpression"
|| node.callee.computed
node.callee.type !== "MemberExpression" ||
node.callee.computed ||
// allow static method calls
|| node.callee.object.name === "Array"
|| node.callee.object.name === "Object"
node.callee.object.name === "Array" ||
node.callee.object.name === "Object"
) {
return;
}
Expand All @@ -53,8 +53,7 @@ module.exports = {
},
node: node
});
}
else if (DISALLOWED_ARRAY_PROPS.indexOf(propName) > -1) {
} else if (DISALLOWED_ARRAY_PROPS.indexOf(propName) > -1) {
context.report({
message: "Do not access {{obj}} prototype method '{{prop}}' from target object.",
loc: node.callee.property.loc.start,
Expand Down
2 changes: 1 addition & 1 deletion lib/sinon.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var apiMethods = {
createFakeServer: nise.fakeServer.create.bind(nise.fakeServer),
createFakeServerWithClock: nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock),

addBehavior: function (name, fn) {
addBehavior: function(name, fn) {
behavior.addBehavior(stub, name, fn);
}
};
Expand Down
45 changes: 22 additions & 23 deletions lib/sinon/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var assert;
function verifyIsStub() {
var args = arraySlice(arguments);

forEach(args, function (method) {
forEach(args, function(method) {
if (!method) {
assert.fail("fake is not a spy");
}
Expand All @@ -46,8 +46,12 @@ function verifyIsValidAssertion(assertionMethod, assertionArgs) {
case "calledTwice":
case "calledThrice":
if (assertionArgs.length !== 0) {
assert.fail(assertionMethod +
" takes 1 argument but was called with " + (assertionArgs.length + 1) + " arguments");
assert.fail(
assertionMethod +
" takes 1 argument but was called with " +
(assertionArgs.length + 1) +
" arguments"
);
}
break;
default:
Expand All @@ -69,7 +73,7 @@ function mirrorPropAsAssertion(name, method, message) {
meth = name;
}

assert[name] = function (fake) {
assert[name] = function(fake) {
verifyIsStub(fake);

var args = arraySlice(arguments, 1);
Expand All @@ -80,8 +84,7 @@ function mirrorPropAsAssertion(name, method, message) {
if (typeof meth === "function") {
failed = !meth(fake);
} else {
failed = typeof fake[meth] === "function" ?
!fake[meth].apply(fake, args) : !fake[meth];
failed = typeof fake[meth] === "function" ? !fake[meth].apply(fake, args) : !fake[meth];
}

if (failed) {
Expand All @@ -93,10 +96,7 @@ function mirrorPropAsAssertion(name, method, message) {
}

function exposedName(prefix, prop) {
return !prefix || /^fail/.test(prop)
? prop
: prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1)
;
return !prefix || /^fail/.test(prop) ? prop : prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1);
}

assert = {
Expand Down Expand Up @@ -133,8 +133,7 @@ assert = {
// If this fails, we'll just fall back to the blank string
}

failAssertion(this, "expected " + expected + " to be " +
"called in order but were called as " + actual);
failAssertion(this, "expected " + expected + " to be " + "called in order but were called as " + actual);
} else {
assert.pass("callOrder");
}
Expand All @@ -144,8 +143,7 @@ assert = {
verifyIsStub(method);

if (method.callCount !== count) {
var msg = "expected %n to be called " + timesInWords(count) +
" but was called %c%C";
var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C";
failAssertion(this, method.printf(msg));
} else {
assert.pass("callCount");
Expand All @@ -158,11 +156,11 @@ assert = {
}

var o = options || {};
var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix;
var prefix = (typeof o.prefix === "undefined" && "assert") || o.prefix;
var includeFail = typeof o.includeFail === "undefined" || Boolean(o.includeFail);
var instance = this;

forEach(Object.keys(instance), function (method) {
forEach(Object.keys(instance), function(method) {
if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) {
target[exposedName(prefix, method)] = instance[method];
}
Expand All @@ -188,17 +186,18 @@ assert = {
};

mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
mirrorPropAsAssertion("notCalled", function (spy) {
return !spy.called;
}, "expected %n to not have been called but was called %c%C");
mirrorPropAsAssertion(
"notCalled",
function(spy) {
return !spy.called;
},
"expected %n to not have been called but was called %c%C"
);
mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
mirrorPropAsAssertion(
"alwaysCalledOn",
"expected %n to always be called with %1 as this but was called with %t"
);
mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t");
mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D");
Expand Down
54 changes: 27 additions & 27 deletions lib/sinon/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ function getCallback(behavior, args) {
return argumentList[i];
}

if (callArgProp && argumentList[i] &&
typeof argumentList[i][callArgProp] === "function") {
if (callArgProp && argumentList[i] && typeof argumentList[i][callArgProp] === "function") {
return argumentList[i][callArgProp];
}
}
Expand All @@ -53,12 +52,13 @@ function getCallbackError(behavior, func, args) {
var msg;

if (behavior.callArgProp) {
msg = functionName(behavior.stub) +
" expected to yield to '" + valueToString(behavior.callArgProp) +
msg =
functionName(behavior.stub) +
" expected to yield to '" +
valueToString(behavior.callArgProp) +
"', but no object with such a property was passed.";
} else {
msg = functionName(behavior.stub) +
" expected to yield, but no callback was passed.";
msg = functionName(behavior.stub) + " expected to yield, but no callback was passed.";
}

if (args.length > 0) {
Expand All @@ -79,9 +79,7 @@ function ensureArgs(name, behavior, args) {

if (index >= args.length) {
throw new TypeError(
name + " failed: " + (index + 1)
+ " arguments required but only " + args.length
+ " present"
name + " failed: " + (index + 1) + " arguments required but only " + args.length + " present"
);
}
}
Expand All @@ -96,7 +94,7 @@ function callCallback(behavior, args) {
}

if (behavior.callbackAsync) {
nextTick(function () {
nextTick(function() {
func.apply(behavior.callbackContext, behavior.callbackArguments);
});
} else {
Expand All @@ -123,16 +121,18 @@ var proto = {
},

isPresent: function isPresent() {
return (typeof this.callArgAt === "number" ||
this.exception ||
this.exceptionCreator ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.resolveArgAt === "number" ||
this.resolveThis ||
typeof this.throwArgAt === "number" ||
this.fakeFn ||
this.returnValueDefined);
return (
typeof this.callArgAt === "number" ||
this.exception ||
this.exceptionCreator ||
typeof this.returnArgAt === "number" ||
this.returnThis ||
typeof this.resolveArgAt === "number" ||
this.resolveThis ||
typeof this.throwArgAt === "number" ||
this.fakeFn ||
this.returnValueDefined
);
},

invoke: function invoke(context, args) {
Expand Down Expand Up @@ -198,39 +198,39 @@ var proto = {

withArgs: function withArgs(/* arguments */) {
throw new Error(
"Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " +
"is not supported. Use \"stub.withArgs(...).onCall(...)\" " +
"to define sequential behavior for calls with certain arguments."
'Defining a stub by invoking "stub.onCall(...).withArgs(...)" ' +
'is not supported. Use "stub.withArgs(...).onCall(...)" ' +
"to define sequential behavior for calls with certain arguments."
);
}
};

function createAsyncVersion(syncFnName) {
return function () {
return function() {
var result = this[syncFnName].apply(this, arguments);
this.callbackAsync = true;
return result;
};
}

// create asynchronous versions of callsArg* and yields* methods
forEach(Object.keys(proto), function (method) {
forEach(Object.keys(proto), function(method) {
// need to avoid creating anotherasync versions of the newly added async methods
if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
proto[method + "Async"] = createAsyncVersion(method);
}
});

function createBehavior(behaviorMethod) {
return function () {
return function() {
this.defaultBehavior = this.defaultBehavior || proto.create(this);
this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments);
return this;
};
}

function addBehavior(stub, name, fn) {
proto[name] = function () {
proto[name] = function() {
fn.apply(this, concat([this], slice(arguments)));
return this.stub || this;
};
Expand Down
4 changes: 2 additions & 2 deletions lib/sinon/blob.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*global Blob */
"use strict";

exports.isSupported = (function () {
exports.isSupported = (function() {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}());
})();
Loading

0 comments on commit 6f48865

Please sign in to comment.