import type { TSESTree } from '@typescript-eslint/utils'; export type HookArgCheck = { allowedHookCalls: Set; errors: { messageId: MessageId; node: TSESTree.Node; }[]; }; /** * Determines whether a call expression represents a hook call by inspecting its callee. * It unwraps the callee expression before checking to ensure nested expressions are handled. * This is used to simplify hook detection logic throughout the rule utilities. * * @param node The call expression to evaluate. * @returns Whether the call expression resolves to a hook callee. * * @example * ```tsx * const isHook = isHookCall(callExpression); * ``` */ export declare const isHookCall: (node: TSESTree.CallExpression) => boolean; /** * Checks whether a call expression matches a Cypress command on the `cy` object. * It unwraps the callee to handle nested expressions and verifies both the object and property names. * This helps enforce command-specific validations in the rule set. * * @param node The call expression to inspect. * @param command The Cypress command name to match. * @returns Whether the call expression is a `cy.` call. * * @example * ```tsx * const isMount = isCyCommandCall(callExpression, 'mount'); * ``` */ export declare const isCyCommandCall: (node: TSESTree.CallExpression, command: string) => boolean; /** * Determines whether a call expression represents a Cypress mount hook invocation. * It checks both the singular and plural command names to cover supported API variants. * This helper centralizes the logic so other utilities can rely on a consistent predicate. * * @param node The call expression to inspect. * @returns Whether the call expression is a mount hook command call. * * @example * ```tsx * const isMountHook = isMountHookCall(callExpression); * ``` */ export declare const isMountHookCall: (node: TSESTree.CallExpression) => boolean; /** * Verifies that a call expression represents a `then` chain call on a specific target expression. * It unwraps the callee to correctly handle nested or parenthesized expressions. * This ensures the comparison against the target is precise and consistent. * * @param node The call expression to inspect. * @param target The target expression that must be the member object. * @returns Whether the call expression is a `then` call on the target. * * @example * ```tsx * const isThen = isThenCall(callExpression, mountCall); * ``` */ export declare const isThenCall: (node: TSESTree.CallExpression, target: TSESTree.Expression) => boolean; /** * Collects the chained `then` call expressions that follow a Cypress mount call. * It walks upward through the parent member expressions to find `then` calls and records each call in order. * This helper stops as soon as the chain no longer matches the expected `then` pattern to ensure the result is precise. * * @param mountCall The initial mount call expression to inspect for chained `then` calls. * @returns An array of `then` call expressions chained from the provided mount call. * * @example * ```tsx * const thens = getThenChain(mountCall); * ``` */ export declare const getThenChain: (mountCall: TSESTree.CallExpression) => TSESTree.CallExpression[]; /** * Extracts a hook call expression from an arrow function body when possible. * It supports concise bodies and single return statements within block bodies. * This helper ensures only valid hook calls are returned while everything else resolves to null. * * @param node The arrow function expression to inspect. * @returns The hook call expression when found, otherwise null. * * @remarks * This utility only accepts arrow functions and enforces a narrow shape for safe extraction. * * @example * ```tsx * const hookCall = getHookCallFromArrow(arrowFunction); * ``` */ export declare const getHookCallFromArrow: (node: TSESTree.ArrowFunctionExpression) => TSESTree.CallExpression | null; /** * Validates Cypress mount hook arguments and reports any rule violations that are detected. * It inspects the call signature to ensure the correct argument count and acceptable argument shapes. * It also collects valid hook call expressions so downstream checks can reuse the results safely. * * @param node The call expression whose arguments are validated for mount hook usage. * @param messageIds The message identifiers used for reporting invalid or missing arguments. * @param messageIds.invalidHookArgument The message ID for reporting invalid hook arguments. * @param messageIds.missingHooksArgs The message ID for reporting missing arguments when using the plural mount hooks command. * @returns The collected allowed hook calls along with any validation errors. * * @example * ```tsx * const result = checkHookArguments(callExpression, { * invalidHookArgument: 'invalidHookArgument', * missingHooksArgs: 'missingHooksArgs' * }); * ``` */ export declare const checkHookArguments: (node: TSESTree.CallExpression, messageIds: { invalidHookArgument: MessageId; missingHooksArgs: MessageId; }) => HookArgCheck; /** * Determines whether a node represents a Cypress `cy.wrap(values).as('values')` call pattern. * It inspects the call expression structure and validates the chained member access and arguments. * This helper keeps the rule logic consistent by providing a single predicate for the expected wrap-and-alias sequence. * * @param node The AST node to inspect for a wrap values call pattern. * @returns True when the node matches the expected `cy.wrap(values).as('values')` call chain. * * @example * ```tsx * if (hasWrapValues(callExpression)) { * // handle wrap values call * } * ``` */ export declare const hasWrapValues: (node: TSESTree.Node) => boolean; /** * Determines whether a given AST node contains a JSX element named `MockComponent`. * It inspects JSX elements and fragments recursively to locate the target component in nested structures. * It returns a boolean so callers can quickly decide if a mount or render includes the mock component. * * @param node The AST node to inspect for the `MockComponent` JSX element. * @returns True when a `MockComponent` JSX element is found, otherwise false. * * @remarks * This utility only traverses JSXElement and JSXFragment nodes and ignores other node types. * * @example * ```tsx * const hasMock = containsMockComponent(jsxNode); * ``` */ export declare const containsMockComponent: (node: TSESTree.Node | null | undefined) => boolean; /** * Determines whether a call expression represents a Cypress `cy.mount` call that includes a mock component. * It validates that the node is a call expression and that the call targets the `mount` command on `cy`. * It then inspects the first argument to confirm the presence of a `MockComponent` JSX element. * * @param node The AST node to inspect for a mount call containing a mock component. * @returns True when the node is a `cy.mount` call with a mock component argument; otherwise false. * * @example * ```tsx * const hasMockMount = hasMountWithMock(callExpression); * ``` */ export declare const hasMountWithMock: (node: TSESTree.Node) => boolean; /** * Determines whether the provided AST node represents an assertion-style call. * It checks for direct `expect(...)` calls as well as chained calls that use `assert` or `should` identifiers. * This helper centralizes assertion detection so other utilities can rely on a consistent predicate. * * @param node The AST node to inspect for an assertion call signature. * @returns True when the node matches known assertion call shapes; otherwise false. * * @remarks * This function only inspects call expressions and their immediate callee shapes. * * @example * ```tsx * if (hasAssertionCall(node)) { * // handle assertion * } * ``` */ export declare const hasAssertionCall: (node: TSESTree.Node) => boolean; /** * Determines whether a statement is a valid first `then` chain entry for mount-related checks. * It only allows expression statements that call either the wrap-values helper or the mount-with-mock helper. * This keeps downstream validation focused on the allowed call patterns and avoids unrelated statements. * * @param statement The statement node to validate against the allowed `then`-body patterns. * @returns True when the statement is a call expression to `hasWrapValues` or `hasMountWithMock`. * * @remarks * This helper enforces a strict shape so the rule can reason about the order of mount and wrap calls. * * @example * ```tsx * if (isAllowedFirstThenStatement(statement)) { * // process allowed statement * } * ``` */ export declare const isAllowedFirstThenStatement: (statement: TSESTree.Statement) => boolean; /** * Performs a depth-first traversal of an AST node and all of its descendants. * The traversal is iterative and uses a stack to avoid recursion limits while still visiting every reachable child * node. The visitor callback is invoked for each node encountered, and the traversal skips parent references to prevent * cycles. * * @param node The root AST node to start walking from. * @param visitor The callback invoked for each visited AST node. * * @remarks * This helper treats any object with a `type` property as a node and walks arrays of nodes as well. * It intentionally skips the `parent` property to avoid infinite loops. The traversal order is depth-first but * not guaranteed to be stable for sibling ordering. * * @example * ```tsx * walk(rootNode, child => { * if (child.type === 'CallExpression') { * // handle call expressions * } * }); * ``` */ export declare const walk: (node: TSESTree.Node, visitor: (child: TSESTree.Node) => void) => void; /** * Determines whether a call expression represents a test `it` invocation. This includes direct `it(...)` calls as * well as `it.only(...)` and `it.skip(...)` variants. It unwraps the callee to handle nested expressions and returns * a boolean predicate for downstream rule logic. * * @param node The call expression to inspect. * @returns True when the call expression targets `it`, `it.only`, or `it.skip`; otherwise false. * * @remarks * This helper only inspects the immediate callee shape and does not validate arguments. * * @example * ```tsx * const isTestCall = isItCall(callExpression); * ``` */ export declare const isItCall: (node: TSESTree.CallExpression) => boolean; /** * Determines whether a callback node matches the expected `then` signature for mount hook utilities. It validates that * the node is a function expression with an object pattern parameter and that it exposes both `MockComponent` and * `values` bindings. It returns the original callback node when the signature is valid, otherwise it returns null. * * @param callback The AST node to validate as a `then` callback. * @returns The callback node when valid; otherwise null. * * @example * ```tsx * const validCallback = isThenCallbackValid(node); * ``` */ export declare const isThenCallbackValid: (callback: TSESTree.Node | null | undefined) => TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionExpression | null; /** * Determines whether a call expression represents a Cypress `invoke` call chained from a values * `its('current')` lookup. It unwraps the callee and validates that the property name is `invoke` before checking the * call chain. It returns a boolean so callers can quickly detect the expected Cypress pattern without additional traversal. * * @param node The call expression to inspect for a values `invoke` chain. * @returns True when the call expression is an `invoke` call chained from a valid values current access; otherwise false. * * @remarks * This helper only inspects member expression callees and relies on `hasValuesCurrentInChain` for recursive chain validation. * * @example * ```tsx * const isInvoke = isValuesInvokeCall(callExpression); * ``` */ export declare const isValuesInvokeCall: (node: TSESTree.CallExpression) => boolean; /** * Determines whether a callback body contains a values `invoke` call in its AST subtree. It walks the block statement * iteratively to avoid callback-based traversal while still visiting every descendant node. It returns true as soon as * a matching `cy.get('@values').its('current').invoke(...)` chain is detected. * * @param callback The function expression to inspect for a values invoke call chain. * @returns True when a values invoke call is found in the callback body; otherwise false. * * @example * ```tsx * const hasInvoke = hasValuesInvokeInCallback(callbackNode); * ``` */ export declare const hasValuesInvokeInCallback: (callback: TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression) => boolean; /** * Analyzes the first `then` callback body for mount/wrap usage, assertions, * invalid statements, and invalid ordering between wrap and mount calls. * * @param callback The `then` callback function expression to inspect. * @returns An object describing whether the callback contains assertions, invalid statements, invalid ordering, and the presence of mount/wrap usage. */ export declare const checkFirstThenBody: (callback: TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression) => { hasAssertion: boolean; hasInvalidOrder: boolean; hasInvalidStatement: boolean; hasMount: boolean; hasWrap: boolean; };