📄 isArrayMethodCallWithPredicate¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 6 |
| 📊 Variables & Constants | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/isArrayMethodCallWithPredicate.ts
📦 Imports¶
| Name | Source |
|---|---|
ParserServicesWithTypeInformation |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
RuleContext |
@typescript-eslint/utils/ts-eslint |
getConstrainedTypeAtLocation |
@typescript-eslint/type-utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
getStaticMemberAccessValue |
./misc |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
ARRAY_PREDICATE_FUNCTIONS |
Set<unknown> |
const | new Set<unknown>([ 'every', 'filter', 'find', 'findIndex', 'findLast', 'findL... |
✗ |
Functions¶
isArrayMethodCallWithPredicate(context: RuleContext<string, unknown[]>, services: ParserServicesWithTypeInformation, node: TSESTree.CallExpression): boolean¶
Parameters:
contextRuleContext<string, unknown[]>servicesParserServicesWithTypeInformationnodeTSESTree.CallExpression
Returns: boolean
Calls:
getStaticMemberAccessValue (from ./misc)ARRAY_PREDICATE_FUNCTIONS.hasservices.program.getTypeCheckergetConstrainedTypeAtLocation (from @typescript-eslint/type-utils)tsutils .unionConstituents(type) .flatMap(part => tsutils.intersectionConstituents(part)) .somechecker.isArrayTypechecker.isTupleType
Code
export function isArrayMethodCallWithPredicate(
context: RuleContext<string, unknown[]>,
services: ParserServicesWithTypeInformation,
node: TSESTree.CallExpression,
): boolean {
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) {
return false;
}
const staticAccessValue = getStaticMemberAccessValue(node.callee, context);
if (!ARRAY_PREDICATE_FUNCTIONS.has(staticAccessValue)) {
return false;
}
const checker = services.program.getTypeChecker();
const type = getConstrainedTypeAtLocation(services, node.callee.object);
return tsutils
.unionConstituents(type)
.flatMap(part => tsutils.intersectionConstituents(part))
.some(t => checker.isArrayType(t) || checker.isTupleType(t));
}
Generated by Syntax Scribe