Skip to content

Commit

Permalink
Fix lint violations for no-param-reassign
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Oct 8, 2018
1 parent 6204505 commit 5cc5dd9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 44 deletions.
22 changes: 12 additions & 10 deletions lib/sinon/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ function verifyIsValidAssertion(assertionMethod, assertionArgs) {
}

function failAssertion(object, msg) {
object = object || global;
var failMethod = object.fail || assert.fail;
failMethod.call(object, msg);
var obj = object || global;
var failMethod = obj.fail || assert.fail;
failMethod.call(obj, msg);
}

function mirrorPropAsAssertion(name, method, message) {
var msg = message;
var meth = method;
if (arguments.length === 2) {
message = method;
method = name;
msg = method;
meth = name;
}

assert[name] = function (fake) {
Expand All @@ -75,15 +77,15 @@ function mirrorPropAsAssertion(name, method, message) {

verifyIsValidAssertion(name, args);

if (typeof method === "function") {
failed = !method(fake);
if (typeof meth === "function") {
failed = !meth(fake);
} else {
failed = typeof fake[method] === "function" ?
!fake[method].apply(fake, args) : !fake[method];
failed = typeof fake[meth] === "function" ?
!fake[meth].apply(fake, args) : !fake[meth];
}

if (failed) {
failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([message], args)));
failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([msg], args)));
} else {
assert.pass(name);
}
Expand Down
14 changes: 8 additions & 6 deletions lib/sinon/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,34 @@ function match(expectation, message) {
}

matcher.or = function (m2) {
var matcher2 = m2;
if (!arguments.length) {
throw new TypeError("Matcher expected");
} else if (!isMatcher(m2)) {
m2 = match(m2);
matcher2 = match(m2);
}
var m1 = this;
var or = Object.create(matcher);
or.test = function (actual) {
return m1.test(actual) || m2.test(actual);
return m1.test(actual) || matcher2.test(actual);
};
or.message = m1.message + ".or(" + m2.message + ")";
or.message = m1.message + ".or(" + matcher2.message + ")";
return or;
};

matcher.and = function (m2) {
var matcher2 = m2;
if (!arguments.length) {
throw new TypeError("Matcher expected");
} else if (!isMatcher(m2)) {
m2 = match(m2);
matcher2 = match(m2);
}
var m1 = this;
var and = Object.create(matcher);
and.test = function (actual) {
return m1.test(actual) && m2.test(actual);
return m1.test(actual) && matcher2.test(actual);
};
and.message = m1.message + ".and(" + m2.message + ")";
and.message = m1.message + ".and(" + matcher2.message + ")";
return and;
};

Expand Down
11 changes: 6 additions & 5 deletions lib/sinon/mock-expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,24 @@ var mockExpectation = {
return true;
}

args = args || [];
// eslint-disable-next-line no-underscore-dangle
var _args = args || [];

if (args.length < expectedArguments.length) {
if (_args.length < expectedArguments.length) {
return false;
}

if (this.expectsExactArgCount &&
args.length !== expectedArguments.length) {
_args.length !== expectedArguments.length) {
return false;
}

return every(expectedArguments, function (expectedArgument, i) {
if (!verifyMatcher(expectedArgument, args[i])) {
if (!verifyMatcher(expectedArgument, _args[i])) {
return false;
}

if (!deepEqual(expectedArgument, args[i])) {
if (!deepEqual(expectedArgument, _args[i])) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/sinon/spy-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ var map = arrayProto.map;
var push = arrayProto.push;

function colorSinonMatchText(matcher, calledArg, calledArgMessage) {
var calledArgumentMessage = calledArgMessage;
if (!matcher.test(calledArg)) {
matcher.message = color.red(matcher.message);
if (calledArgMessage) {
calledArgMessage = color.green(calledArgMessage);
if (calledArgumentMessage) {
calledArgumentMessage = color.green(calledArgumentMessage);
}
}
return calledArgMessage + " " + matcher.message;
return calledArgumentMessage + " " + matcher.message;
}

function colorDiffText(diff) {
Expand Down
19 changes: 9 additions & 10 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,26 @@ var spyApi = {

create: function create(func, spyLength) {
var name;
var funk = func;

if (typeof func !== "function") {
func = function () {

if (typeof funk !== "function") {
funk = function () {
return;
};
} else {
name = functionName(func);
}

if (!spyLength) {
spyLength = func.length;
name = functionName(funk);
}

var proxy = createProxy(func, spyLength);
var length = spyLength || funk.length;
var proxy = createProxy(funk, length);

extend(proxy, spy);
delete proxy.create;
extend(proxy, func);
extend(proxy, funk);

proxy.resetHistory();
proxy.prototype = func.prototype;
proxy.prototype = funk.prototype;
proxy.displayName = name || "spy";
proxy.toString = functionToString;
proxy.instantiateFake = spy.create;
Expand Down
12 changes: 5 additions & 7 deletions lib/sinon/util/core/called-in-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var every = Array.prototype.every;

module.exports = function calledInOrder(spies) {
var callMap = {};
// eslint-disable-next-line no-underscore-dangle
var _spies = arguments.length > 1 ? arguments : spies;

function hasCallsLeft(spy) {
if (callMap[spy.id] === undefined) {
Expand All @@ -13,15 +15,11 @@ module.exports = function calledInOrder(spies) {
return callMap[spy.id] < spy.callCount;
}

if (arguments.length > 1) {
spies = arguments;
}

return every.call(spies, function checkAdjacentCalls(spy, i) {
return every.call(_spies, function checkAdjacentCalls(spy, i) {
var calledBeforeNext = true;

if (i !== spies.length - 1) {
calledBeforeNext = spy.calledBefore(spies[i + 1]);
if (i !== _spies.length - 1) {
calledBeforeNext = spy.calledBefore(_spies[i + 1]);
}

if (hasCallsLeft(spy) && calledBeforeNext) {
Expand Down
5 changes: 2 additions & 3 deletions lib/sinon/util/core/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnPropert
module.exports = function getConfig(custom) {
var config = {};
var prop;

custom = custom || {};
var kustom = custom || {};

for (prop in defaultConfig) {
if (hasOwnProperty(defaultConfig, prop)) {
config[prop] = hasOwnProperty(custom, prop) ? custom[prop] : defaultConfig[prop];
config[prop] = hasOwnProperty(kustom, prop) ? kustom[prop] : defaultConfig[prop];
}
}

Expand Down

0 comments on commit 5cc5dd9

Please sign in to comment.