Skip to content

Commit

Permalink
Chore: Replace some function application with spread operators (eslin…
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure authored and not-an-aardvark committed Jul 22, 2018
1 parent b6daf0e commit 0cb5e3e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/rules/key-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ module.exports = {
const length = properties.length,
widths = properties.map(getKeyWidth), // Width of keys, including quotes
align = alignmentOptions.on; // "value" or "colon"
let targetWidth = Math.max.apply(null, widths),
let targetWidth = Math.max(...widths),
beforeColon, afterColon, mode;

if (alignmentOptions && length > 1) { // When aligning values within a group, use the alignment configuration.
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unmodified-loop-condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Traverser = require("../util/traverser"),
// Helpers
//------------------------------------------------------------------------------

const pushAll = Function.apply.bind(Array.prototype.push);
const SENTINEL_PATTERN = /(?:(?:Call|Class|Function|Member|New|Yield)Expression|Statement|Declaration)$/;
const LOOP_PATTERN = /^(?:DoWhile|For|While)Statement$/; // for-in/of statements don't have `test` property.
const GROUP_PATTERN = /^(?:BinaryExpression|ConditionalExpression)$/;
Expand Down Expand Up @@ -356,7 +355,7 @@ module.exports = {
let scope;

while ((scope = queue.pop())) {
pushAll(queue, scope.childScopes);
queue.push(...scope.childScopes);
scope.variables.forEach(checkReferences);
}

Expand Down
11 changes: 1 addition & 10 deletions lib/rules/no-useless-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ const astUtils = require("../ast-utils"),
// Helpers
//------------------------------------------------------------------------------

/**
* Adds all elements of 2nd argument into 1st argument.
*
* @param {Array} array - The destination array to add.
* @param {Array} elements - The source array to add.
* @returns {void}
*/
const pushAll = Function.apply.bind(Array.prototype.push);

/**
* Removes the given element from the array.
*
Expand Down Expand Up @@ -137,7 +128,7 @@ module.exports = {
continue;
}

pushAll(uselessReturns, segmentInfoMap.get(segment).uselessReturns);
uselessReturns.push(...segmentInfoMap.get(segment).uselessReturns);
}

return uselessReturns;
Expand Down
11 changes: 1 addition & 10 deletions lib/rules/prefer-const.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ const PATTERN_TYPE = /^(?:.+?Pattern|RestElement|SpreadProperty|ExperimentalRest
const DECLARATION_HOST_TYPE = /^(?:Program|BlockStatement|SwitchCase)$/;
const DESTRUCTURING_HOST_TYPE = /^(?:VariableDeclarator|AssignmentExpression)$/;

/**
* Adds multiple items to the tail of an array.
*
* @param {any[]} array - A destination to add.
* @param {any[]} values - Items to be added.
* @returns {void}
*/
const pushAll = Function.apply.bind(Array.prototype.push);

/**
* Checks whether a given node is located at `ForStatement.init` or not.
*
Expand Down Expand Up @@ -364,7 +355,7 @@ module.exports = {

VariableDeclaration(node) {
if (node.kind === "let" && !isInitOfForStatement(node)) {
pushAll(variables, context.getDeclaredVariables(node));
variables.push(...context.getDeclaredVariables(node));
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions lib/testers/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const IT = Symbol("it");
*/
function itDefaultHandler(text, method) {
try {
return method.apply(this);
return method.call(this);
} catch (err) {
if (err instanceof assert.AssertionError) {
err.message += ` (${util.inspect(err.actual)} ${err.operator} ${util.inspect(err.expected)})`;
Expand All @@ -157,7 +157,7 @@ function itDefaultHandler(text, method) {
* @returns {any} Returned value of `method`.
*/
function describeDefaultHandler(text, method) {
return method.apply(this);
return method.call(this);
}

class RuleTester {
Expand Down
6 changes: 3 additions & 3 deletions lib/util/node-event-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function getPossibleTypes(parsedSelector) {
case "matches": {
const typesForComponents = parsedSelector.selectors.map(getPossibleTypes);

if (typesForComponents.every(typesForComponent => typesForComponent)) {
return lodash.union.apply(null, typesForComponents);
if (typesForComponents.every(Boolean)) {
return lodash.union(...typesForComponents);
}
return null;
}
Expand All @@ -63,7 +63,7 @@ function getPossibleTypes(parsedSelector) {
* If at least one of the components could only match a particular type, the compound could only match
* the intersection of those types.
*/
return lodash.intersection.apply(null, typesForComponents);
return lodash.intersection(...typesForComponents);
}

case "child":
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-invalid-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function extractPatterns(patterns, type) {
}));

// Flatten.
return Array.prototype.concat.apply([], patternsList);
return [].concat(...patternsList);
}


Expand Down
4 changes: 2 additions & 2 deletions tests/lib/testers/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const ruleTesterTestEmitter = new EventEmitter();

RuleTester.describe = function(text, method) {
ruleTesterTestEmitter.emit("describe", text, method);
return method.apply(this);
return method.call(this);
};

RuleTester.it = function(text, method) {
ruleTesterTestEmitter.emit("it", text, method);
return method.apply(this);
return method.call(this);
};

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 0cb5e3e

Please sign in to comment.