/** * Validate Catch Error Pattern Executor * * Validates that catch blocks follow the standardized error handling pattern. * Uses TypeScript AST for detection and LINE-BASED git diff filtering. * * ============================================================================ * REQUIRED PATTERN * ============================================================================ * * Standard: catch (err: unknown) { const error = toError(err); ... } * Ignored: catch (err: unknown) { //const error = toError(err); ... } * Nested: catch (err2: unknown) { const error2 = toError(err2); ... } * * ============================================================================ * VIOLATIONS (BAD) - These patterns are flagged: * ============================================================================ * * - catch (e) { ... } — wrong parameter name * - catch (err) { ... } — missing : unknown type annotation * - catch (err: unknown) { ... } — missing toError() as first statement * - catch (err: unknown) { const x = toError(err); } — wrong variable name * * ============================================================================ * MODES (LINE-BASED) * ============================================================================ * - OFF: Skip validation entirely * - MODIFIED_CODE: Flag catch violations on changed lines (lines in diff hunks) * - MODIFIED_FILES: Flag ALL catch violations in files that were modified * * ============================================================================ * ESCAPE HATCH * ============================================================================ * Add comment above the violation: * // webpieces-disable catch-error-pattern -- [your justification] * } catch (err: unknown) { */ import type { ExecutorContext } from '@nx/devkit'; export type CatchErrorPatternMode = 'OFF' | 'MODIFIED_CODE' | 'MODIFIED_FILES'; export interface ValidateCatchErrorPatternOptions { mode?: CatchErrorPatternMode; disableAllowed?: boolean; ignoreModifiedUntilEpoch?: number; } export interface ExecutorResult { success: boolean; } export default function runExecutor(options: ValidateCatchErrorPatternOptions, context: ExecutorContext): Promise;