/** * Validate No Direct API in Resolver Executor * * Validates two Angular anti-patterns using LINE-BASED detection: * * ============================================================================ * VIOLATIONS (BAD) - These patterns are flagged: * ============================================================================ * * 1. In *.routes.ts files: inject(XxxApi) — resolvers should inject services, not APIs directly * 2. In *.component.ts files: this..snapshot.data — components should subscribe to * service BehaviorSubjects, not read route snapshot data * * ============================================================================ * CORRECT PATTERNS (GOOD) * ============================================================================ * * 1. In resolvers: inject(XxxService) which calls the API internally * 2. In components: this.myService.someObservable$ (subscribe to service BehaviorSubjects) * * ============================================================================ * MODES (LINE-BASED) * ============================================================================ * - OFF: Skip validation entirely * - MODIFIED_CODE: Flag violations on changed lines (lines in diff hunks) * - NEW_AND_MODIFIED_METHODS: Flag violations in new/modified method/route scopes * - MODIFIED_FILES: Flag ALL violations in files that were modified * * ============================================================================ * ESCAPE HATCH * ============================================================================ * Add comment above the violation: * // webpieces-disable no-direct-api-resolver -- [your justification] * const myApi = inject(MyApi); */ import type { ExecutorContext } from '@nx/devkit'; export type NoDirectApiResolverMode = 'OFF' | 'MODIFIED_CODE' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES'; export interface ValidateNoDirectApiResolverOptions { mode?: NoDirectApiResolverMode; disableAllowed?: boolean; ignoreModifiedUntilEpoch?: number; enforcePaths?: string[]; } export interface ExecutorResult { success: boolean; } export default function runExecutor(options: ValidateNoDirectApiResolverOptions, context: ExecutorContext): Promise;