import type { Maybe } from '@dereekb/util'; /** * Module that holds Angular component decorators. */ export declare const ANGULAR_CORE_MODULE = "@angular/core"; /** * Decorators that mark a class with a component-scoped DestroyRef lifecycle. * * `@Injectable` is intentionally excluded — services often expose long-lived * Subjects as part of their public API and cleaning them on destroy is wrong. */ export declare const ANGULAR_COMPONENT_DECORATORS: ReadonlySet; /** * Module that holds the dbx-components RxJS extras (SubscriptionObject). */ export declare const DBX_COMPONENTS_RXJS_MODULE = "@dereekb/rxjs"; /** * Module that holds Subject/BehaviorSubject/etc. */ export declare const RXJS_MODULE = "rxjs"; /** * Module that holds the cleanup helpers (cleanSubscription, completeOnDestroy, clean). */ export declare const DBX_COMPONENTS_DBX_CORE_MODULE = "@dereekb/dbx-core"; /** * Identifier name for the `SubscriptionObject` class. */ export declare const SUBSCRIPTION_OBJECT_NAME = "SubscriptionObject"; /** * Identifier names for RxJS Subject classes that should be wrapped with `completeOnDestroy`. */ export declare const SUBJECT_NAMES: ReadonlySet; /** * Helper imported from `@dereekb/dbx-core` that replaces a manual SubscriptionObject creation. */ export declare const CLEAN_SUBSCRIPTION_HELPER = "cleanSubscription"; /** * Helper imported from `@dereekb/dbx-core` that wraps a Subject so it completes on destroy. */ export declare const COMPLETE_ON_DESTROY_HELPER = "completeOnDestroy"; /** * Underlying Destroyable/DestroyFunction primitive helper from `@dereekb/dbx-core`. * * Accepted as a wrapper for `new SubscriptionObject(...)` since `SubscriptionObject` * is `Destroyable`. Not accepted for raw Subjects since those are neither * `Destroyable` nor `DestroyFunction` and would not actually call `.complete()`. */ export declare const CLEAN_HELPER = "clean"; /** * Loose AST node alias used by the rule implementations. */ export type AstNode = any; /** * Per-file registry of import information used by all rules in this plugin. * * Tracks: which local names came from which module, the ImportDeclaration node * for each module (for fix insertion), and the last import declaration in the * file (for inserting brand-new imports after). */ export interface ImportRegistry { /** * Maps source-module string to the set of locally-bound identifiers that came from it. */ readonly bySource: Map>; /** * Maps a local identifier name to the source-module string it was imported from. */ readonly localToSource: Map; /** * Maps source-module string to its ImportDeclaration AST node (for appending specifiers). */ readonly sourceToDeclaration: Map; /** * The last ImportDeclaration node in the file. Used to insert brand-new imports. */ lastImportDeclaration: Maybe; } /** * Creates an empty {@link ImportRegistry}. * * @returns A fresh empty registry. */ export declare function createImportRegistry(): ImportRegistry; /** * Records an `ImportDeclaration` node in the registry. Call from the rule's * `ImportDeclaration` visitor for every import in the file. * * @param registry - The registry to mutate. * @param node - The ImportDeclaration AST node. */ export declare function trackImportDeclaration(registry: ImportRegistry, node: AstNode): void; /** * Returns true when the given local identifier name was imported from the given module. * * @param registry - The import registry built from the file's import declarations. * @param localName - The local identifier (as it appears in code). * @param fromSource - The expected source-module string. * @returns True when the local name maps to the given source. */ export declare function isImportedFrom(registry: ImportRegistry, localName: string, fromSource: string): boolean; /** * Extracts the decorator name from a decorator AST node. * * Handles `@Foo()` (CallExpression) and `@Foo` (Identifier). Returns the empty * string for anything else. * * @param decorator - The decorator AST node. * @returns The decorator name, or empty string when unrecognized. */ export declare function getDecoratorName(decorator: AstNode): string; /** * Returns the first decorator on the class that names a component-tier * Angular decorator (`@Component`, `@Directive`, `@Pipe`) imported from * `@angular/core`, or null when none match. * * @param classNode - The ClassDeclaration / ClassExpression AST node. * @param registry - The file's import registry, used to verify the decorator * identifier really came from `@angular/core` (and not a local alias). * @returns The matching decorator and its name, or null. */ export declare function findAngularComponentDecorator(classNode: AstNode, registry: ImportRegistry): Maybe<{ readonly decorator: AstNode; readonly name: string; }>; /** * Returns the property name of a class member when its key is a simple Identifier or string Literal. * * Returns null for computed/symbol/private keys. * * @param member - A ClassBody member AST node. * @returns The property name, or null when not a simple key. */ export declare function getClassMemberName(member: AstNode): Maybe; /** * Finds the `ngOnDestroy` method declaration on the given class, if any. * * @param classNode - The ClassDeclaration / ClassExpression AST node. * @returns The MethodDefinition AST node for `ngOnDestroy`, or null. */ export declare function findNgOnDestroyMethod(classNode: AstNode): Maybe; /** * If the given expression is a `CallExpression` whose callee is one of the * accepted identifier names, returns the matching name. Otherwise null. * * @param node - The expression AST node. * @param names - The accepted identifier names. * @returns The matched name, or null. * * @example * ``` * isCalledIdentifier(node, ['cleanSubscription', 'clean']) // returns 'cleanSubscription' * ``` */ export declare function isCalledIdentifier(node: AstNode, names: ReadonlySet): Maybe; /** * Returns true when the given AST node is a `this.` MemberExpression. * * @param node - The AST node to check. * @param propName - The expected property name. * @returns True when the node is `this.`. */ export declare function isThisMemberAccess(node: AstNode, propName: string): boolean; /** * Input for {@link ensureNamedImportFix}. */ export interface EnsureNamedImportFixInput { /** * The ESLint RuleFixer. */ readonly fixer: AstNode; /** * The file's import registry. Mutated to record the new import. */ readonly registry: ImportRegistry; /** * The named-import identifier to ensure is present. */ readonly importName: string; /** * The source-module string to import from. */ readonly fromSource: string; } /** * Builds a fix operation that ensures `importName` is imported from * `fromSource` in the file. Returns null when the import is already present. * * Side effect: mutates the registry to mark the import as present, so two * separate report fixes in the same lint pass don't both insert the same import. * * @param input - The fixer, registry, and import names. * @returns A fix operation, or null when the import is already present. */ export declare function ensureNamedImportFix(input: EnsureNamedImportFixInput): Maybe; /** * Returns true when the given PropertyDefinition declares a `static` member. * * @param node - The PropertyDefinition AST node. * @returns True when the node has `static` modifier. */ export declare function isStaticProperty(node: AstNode): boolean; /** * Returns true when the given PropertyDefinition uses `declare` * (`declare readonly foo: T`) — i.e. has no runtime initializer. * * @param node - The PropertyDefinition AST node. * @returns True when the property is declared abstractly. */ export declare function isDeclareProperty(node: AstNode): boolean; /** * The Angular `OnDestroy` lifecycle interface name. */ export declare const ON_DESTROY_INTERFACE_NAME = "OnDestroy"; /** * Match details for an `implements OnDestroy` clause located on a class. */ export interface OnDestroyImplementsMatch { /** * The full list of `implements` specifiers on the class (TSClassImplements nodes). */ readonly allImplements: readonly AstNode[]; /** * The TSClassImplements node for `OnDestroy`. */ readonly clauseSpecifier: AstNode; /** * Index of {@link clauseSpecifier} within {@link allImplements}. */ readonly index: number; } /** * Locates an `implements OnDestroy` clause on the class whose `OnDestroy` * identifier resolves to the import from `@angular/core`. Returns null when * no matching clause exists. * * @param classNode - The ClassDeclaration / ClassExpression AST node. * @param registry - The file's import registry. * @returns The match details, or null. */ export declare function findOnDestroyImplementsClause(classNode: AstNode, registry: ImportRegistry): Maybe; /** * Computes the source range to remove for the given `implements` specifier so * that the surrounding `implements` clause stays well-formed. * * Behavior: * - When the specifier is the only entry, the entire `implements ` clause * is removed, including the leading whitespace before the `implements` * keyword (so `class Foo implements OnDestroy {` becomes `class Foo {`). * - When the specifier is the first of several, the specifier and the * following comma+whitespace are removed. * - Otherwise, the preceding comma+whitespace and the specifier are removed. * * @param match - The `implements OnDestroy` match details. * @param sourceCode - The ESLint sourceCode service. * @returns A `[start, end]` range tuple suitable for `fixer.removeRange`. */ export declare function getImplementsSpecifierRemovalRange(match: OnDestroyImplementsMatch, sourceCode: AstNode): readonly [number, number];