Skip to content

Commit

Permalink
chore(eslint-plugin): slight cleanup of array predicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Retsam committed Feb 7, 2020
1 parent 8f676df commit 9040423
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
Expand Up @@ -288,7 +288,7 @@ export default createRule<Options, MessageId>({
'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`
Expand All @@ -300,10 +300,9 @@ export default createRule<Options, MessageId>({
);
}
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 ||
Expand Down

0 comments on commit 9040423

Please sign in to comment.