@unito/integration-sdk
Version:
Integration SDK
43 lines (42 loc) • 1.77 kB
TypeScript
/**
* Shared AST helpers for `@unito/integration-sdk` ESLint rules. Centralised so
* rules that walk the same shapes (catch clauses, logger member chains,
* HttpErrors call sites) don't drift across rule files.
*/
import type * as ESTree from 'estree';
import type { Rule } from 'eslint';
export declare const HTTP_ERRORS_NAMESPACE = "HttpErrors";
export declare const LOGGER_NAME_BROAD_RE: RegExp;
export declare const LOGGER_NAME_STRICT_RE: RegExp;
export interface MemberChain {
root: string | null;
props: string[];
}
/**
* Walk a (possibly chained) MemberExpression and return its identifier
* components.
*
* foo.bar.baz() → { root: 'foo', props: ['baz', 'bar'] }
* this.x.y → { root: null, props: ['y', 'x'] }
*/
export declare function walkMemberChain(node: ESTree.Node | null | undefined): MemberChain;
/**
* Walks parents from `node` until either:
* - finds a CatchClause (returns true)
* - crosses a function boundary (returns false)
*
* Use to scope rules to lexically-enclosed catch blocks; helpers called from a
* catch via a separate function are intentionally NOT matched.
*/
export declare function isInsideCatchClause(node: Rule.Node): boolean;
/**
* Like isInsideCatchClause but returns the parameter name of the enclosing
* CatchClause. Returns null if the node is not inside a catch, or if the catch
* uses destructuring / has no parameter binding.
*/
export declare function getCatchClauseParam(node: Rule.Node): string | null;
/**
* Returns true if `callee` is a `HttpErrors.<X>` MemberExpression. If `subClass`
* is provided, additionally requires the property name to match.
*/
export declare function isHttpErrorsCallee(callee: ESTree.Node | null | undefined, subClass?: string): boolean;