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 09f54a8 commit ccedabf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 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,12 +300,12 @@ 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 &&
(callback.type === AST_NODE_TYPES.ArrowFunctionExpression ||
callback.type === AST_NODE_TYPES.FunctionExpression) &&
callback.body
Expand Down

0 comments on commit ccedabf

Please sign in to comment.