From 90404234a7a70dad31b39e1d33352a3632527a1c Mon Sep 17 00:00:00 2001 From: Retsam Date: Fri, 7 Feb 2020 15:42:52 -0500 Subject: [PATCH] chore(eslint-plugin): slight cleanup of array predicate logic --- .../eslint-plugin/src/rules/no-unnecessary-condition.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index 0f3fb3d4b92..c6157428b80 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -288,7 +288,7 @@ export default createRule({ 'some', 'every', ]); - function shouldCheckCallback(node: TSESTree.CallExpression): boolean { + function isArrayPredicateFunction(node: TSESTree.CallExpression): boolean { const { callee } = node; return ( // looks like `something.filter` or `something.find` @@ -300,10 +300,9 @@ export default createRule({ ); } function checkCallExpression(node: TSESTree.CallExpression): void { - const { - arguments: [callback], - } = node; - if (callback && shouldCheckCallback(node)) { + // If this is something like arr.filter(x => /*condition*/), check `condition` + if (isArrayPredicateFunction(node) && node.arguments.length) { + const callback = node.arguments[0]!; // Inline defined functions if ( (callback.type === AST_NODE_TYPES.ArrowFunctionExpression ||