From 5cc5dd9b6aa0d282756c3889d1062979ace195c2 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:28:52 +0200 Subject: [PATCH] Fix lint violations for no-param-reassign --- lib/sinon/assert.js | 22 ++++++++++++---------- lib/sinon/match.js | 14 ++++++++------ lib/sinon/mock-expectation.js | 11 ++++++----- lib/sinon/spy-formatters.js | 7 ++++--- lib/sinon/spy.js | 19 +++++++++---------- lib/sinon/util/core/called-in-order.js | 12 +++++------- lib/sinon/util/core/get-config.js | 5 ++--- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 372646f6a..6b29c4f86 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -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) { @@ -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); } diff --git a/lib/sinon/match.js b/lib/sinon/match.js index 81434f031..dfaf2ea74 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -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; }; diff --git a/lib/sinon/mock-expectation.js b/lib/sinon/mock-expectation.js index 1f71dff45..61fab1a32 100644 --- a/lib/sinon/mock-expectation.js +++ b/lib/sinon/mock-expectation.js @@ -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; } diff --git a/lib/sinon/spy-formatters.js b/lib/sinon/spy-formatters.js index 064d995e5..3e0d6d903 100644 --- a/lib/sinon/spy-formatters.js +++ b/lib/sinon/spy-formatters.js @@ -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) { diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index de65b1b7d..1d36815ce 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -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; diff --git a/lib/sinon/util/core/called-in-order.js b/lib/sinon/util/core/called-in-order.js index 862684391..b6b90679d 100644 --- a/lib/sinon/util/core/called-in-order.js +++ b/lib/sinon/util/core/called-in-order.js @@ -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) { @@ -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) { diff --git a/lib/sinon/util/core/get-config.js b/lib/sinon/util/core/get-config.js index 02227e3d0..0936c62a7 100644 --- a/lib/sinon/util/core/get-config.js +++ b/lib/sinon/util/core/get-config.js @@ -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]; } }