Skip to content

Commit

Permalink
Properly check length of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed May 26, 2021
1 parent 85494b8 commit f9c360c
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/rules/no-mocha-arrows.js
Expand Up @@ -92,20 +92,26 @@ module.exports = {
return {
CallExpression(node) {
if (isMochaFunctionCall(node, context.getScope())) {
const fnArg = node.arguments.slice(-1)[0];
if (fnArg && fnArg.type === 'ArrowFunctionExpression') {
const name = astUtils.getNodeName(node.callee);
context.report({
node,
message: `Do not pass arrow functions to ${name}()`,
fix(fixer) {
return fixArrowFunction(
fixer,
sourceCode,
fnArg
);
}
});
const amountOfArguments = node.arguments.length;

if (amountOfArguments > 0) {
const lastArgument =
node.arguments[amountOfArguments - 1];

if (lastArgument.type === 'ArrowFunctionExpression') {
const name = astUtils.getNodeName(node.callee);
context.report({
node,
message: `Do not pass arrow functions to ${name}()`,
fix(fixer) {
return fixArrowFunction(
fixer,
sourceCode,
lastArgument
);
}
});
}
}
}
}
Expand Down

0 comments on commit f9c360c

Please sign in to comment.