/** * @packageDocumentation * Internal shared utilities used by eslint-plugin-typefest rule modules and * plugin wiring. */ import type { UnknownArray } from "type-fest"; import type ts from "typescript"; import { ESLintUtils, type TSESLint, type TSESTree } from "@typescript-eslint/utils"; import type { TypefestConfigReference } from "./typefest-config-references.js"; /** * Parser services and type checker bundle used by typed rules. */ export interface TypedRuleServices { checker: ts.TypeChecker; parserServices: ReturnType; } /** Shared typed-rule context contract used by helper utilities. */ type TypedRuleContext = Readonly>; export type { TypedRuleContext }; type TypefestRuleCreator = ReturnType>; /** * Plugin-specific metadata extensions for `meta.docs`. * * @remarks * `eslint-plugin/require-meta-docs-recommended` expects `meta.docs.recommended` * to be boolean. Preset membership is tracked separately via * `meta.docs.typefestConfigs`. * * `ruleId` and `ruleNumber` are injected centrally by `createTypedRule` for * cataloged `prefer-*` rules. Rule authors should not hand-author those fields * in individual rule modules. */ interface TypefestRuleDocs { recommended?: boolean; requiresTypeChecking?: boolean; ruleId?: string; ruleNumber?: number; typefestConfigs?: readonly TypefestConfigReference[] | TypefestConfigReference; } /** * Rule-creator wrapper used by all plugin rules. * * @remarks * This wrapper automatically registers per-program plugin settings and injects * canonical `meta.docs.ruleId` / `meta.docs.ruleNumber` values for cataloged * public rules. * * @param ruleDefinition - Rule module definition passed to * `ESLintUtils.RuleCreator`. * * @returns Rule module factory output that auto-registers program settings and * preserves the authored rule contract. */ export declare const createTypedRule: TypefestRuleCreator; /** * Retrieve parser services and type checker for typed rules. * * @param context - Rule context from the current lint evaluation. * * @returns Parser services and type checker references bound to the current * program. * * @throws Throws when `parserServices.program` is unavailable, which indicates * the current lint run is not configured for type-aware analysis. */ export declare const getTypedRuleServices: (context: TypedRuleContext) => TypedRuleServices; /** * Determine whether the current lint context has full type information. * * @param context - Rule context from the current lint evaluation. * * @returns `true` when parser services and `program` are available. */ export declare const hasTypeServices: (context: TypedRuleContext) => boolean; /** * Retrieve typed services when available, otherwise return `undefined`. * * @param context - Rule context from the current lint evaluation. * * @returns Typed services when parser services include a TypeScript program. */ export declare const getTypedRuleServicesOrUndefined: (context: TypedRuleContext) => TypedRuleServices | undefined; /** * Determine whether one TypeScript type is assignable to another. * * @remarks * Uses `checker.isTypeAssignableTo` when available and falls back to strict * reference equality if the checker API is unavailable or throws. * * @param checker - TypeScript type checker. * @param sourceType - Candidate source type. * @param targetType - Candidate target type. * * @returns `true` when assignable; otherwise `false`. */ export declare const isTypeAssignableTo: (checker: Readonly, sourceType: Readonly, targetType: Readonly) => boolean; /** * Resolve the type of a signature parameter by index. * * @param options - Signature parameter lookup options. * * - `checker`: TypeScript type checker. * - `index`: Parameter index in the signature. * - `location`: Source location used for contextual type lookup. * - `signature`: Candidate call signature. * * @returns Parameter type when available; otherwise `undefined`. */ export declare const getSignatureParameterTypeAt: (options: Readonly<{ checker: ts.TypeChecker; index: number; location: ts.Node; signature: null | ts.Signature | undefined; }>) => ts.Type | undefined; /** * Determine whether an expression references an unshadowed global identifier. * * @param context - Rule context used for scope resolution. * @param expression - Expression to inspect. * @param identifierName - Expected identifier name. * * @returns `true` when the expression is an Identifier with the expected name * and resolves to the global binding. */ export declare const isGlobalIdentifierNamed: >(context: Readonly>, expression: Readonly, identifierName: string) => expression is TSESTree.Identifier; /** * Determine whether an expression references the global `undefined` binding * (not a shadowed user-defined symbol). * * @param context - Rule context used for scope resolution. * @param expression - Expression to inspect. * * @returns `true` when the expression is an Identifier named `undefined` that * resolves to the global binding. */ export declare const isGlobalUndefinedIdentifier: >(context: Readonly>, expression: Readonly) => expression is TSESTree.Identifier; //# sourceMappingURL=typed-rule.d.ts.map