eslint-plugin-sonarjs
Version:
34 lines (33 loc) • 1.7 kB
TypeScript
/**
* Shared traversal helpers for walking an `expect(...).a.b.c()` style member/call
* chain, used by rules that need to inspect the chain of matcher/modifier names
* hung off an `expect(...)` (or similar) root call.
*/
import type estree from 'estree';
export declare function unwrapChainExpression<T extends estree.Node | estree.Super>(node: T): T | estree.Expression;
/**
* Collects the chain of member names hung off `call`, furthest from the root
* call first, e.g. for `expect(x).not.resolves.toBe(y)` called with the `toBe(y)`
* node, returns
* `{ segments: [{name: 'toBe', ...}, {name: 'resolves', ...}, {name: 'not', ...}], complete: true }`.
* `complete` is `false` when a computed member or non-identifier property was hit
* before reaching the root call, in which case `segments` only holds the
* well-formed prefix collected so far — callers that need the full chain to be
* a recognised, closed set of names (rather than just searching the collected
* prefix for one specific name) should treat an incomplete chain as unresolved.
*/
export declare function collectCallChain(call: estree.CallExpression): {
segments: {
name: string;
node: estree.Node;
}[];
complete: boolean;
};
/**
* Walks down from `call` to the root call of its member/call chain, e.g. for
* `expect(x).not.resolves.toBe(y)` called with the `toBe(y)` node, returns the
* `expect(x)` call. Tolerates computed members and non-identifier properties
* anywhere in the chain, since finding the root call doesn't depend on the
* chain's named segments being fully resolvable.
*/
export declare function getRootCall(call: estree.CallExpression): estree.CallExpression | null;