@webpieces/dev-config 0.2.73 → 0.2.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Validate No Inline Types Executor
3
+ *
4
+ * Validates that inline type literals AND tuple types are not used in type positions.
5
+ * Prefer named types/interfaces/classes for clarity and reusability.
6
+ *
7
+ * ============================================================================
8
+ * VIOLATIONS (BAD) - These patterns are flagged:
9
+ * ============================================================================
10
+ *
11
+ * 1. INLINE TYPE LITERALS { }
12
+ * -------------------------
13
+ * - Inline parameter type: function foo(arg: { x: number }) { }
14
+ * - Inline return type: function foo(): { x: number } { }
15
+ * - Inline variable type: const config: { timeout: number } = { timeout: 5 };
16
+ * - Inline property type: class C { data: { id: number }; }
17
+ * - Inline in union: type T = { x: number } | null;
18
+ * - Inline in intersection: type T = { x: number } & { y: number };
19
+ * - Inline in generic: Promise<{ data: string }>
20
+ * - Inline in array: function foo(): { id: string }[] { }
21
+ * - Nested inline in alias: type T = { data: { nested: number } }; // inner { } flagged
22
+ * - Inline in tuple: type T = [{ x: number }, string];
23
+ *
24
+ * 2. TUPLE TYPES [ ]
25
+ * ----------------
26
+ * - Tuple return type: function foo(): [Items[], number] { }
27
+ * - Tuple parameter type: function foo(arg: [string, number]) { }
28
+ * - Tuple variable type: const result: [Data[], number] = getData();
29
+ * - Tuple in generic: Promise<[Items[], number]>
30
+ * - Tuple in union: type T = [A, B] | null;
31
+ * - Nested tuple: type T = { data: [A, B] };
32
+ *
33
+ * ============================================================================
34
+ * ALLOWED (GOOD) - These patterns pass validation:
35
+ * ============================================================================
36
+ *
37
+ * 1. TYPE ALIAS DEFINITIONS (direct body only)
38
+ * -----------------------------------------
39
+ * - Type alias with literal: type MyConfig = { timeout: number };
40
+ * - Type alias with tuple: type MyResult = [Items[], number];
41
+ * - Interface definition: interface MyData { id: number }
42
+ * - Class definition: class UserData { id: number; name: string; }
43
+ *
44
+ * 2. USING NAMED TYPES
45
+ * ------------------
46
+ * - Named param type: function foo(arg: MyConfig) { }
47
+ * - Named return type: function foo(): MyConfig { }
48
+ * - Named with null: function foo(): MyConfig | null { }
49
+ * - Named with undefined: function foo(): MyConfig | undefined { }
50
+ * - Union of named types: type Either = TypeA | TypeB;
51
+ * - Named in generic: Promise<MyResult>
52
+ * - Named tuple alias: function foo(): MyTupleResult { }
53
+ *
54
+ * 3. PRIMITIVES AND BUILT-INS
55
+ * -------------------------
56
+ * - Primitive types: function foo(): string { }
57
+ * - Primitive arrays: function foo(): string[] { }
58
+ * - Built-in generics: function foo(): Promise<string> { }
59
+ * - Void return: function foo(): void { }
60
+ *
61
+ * ============================================================================
62
+ * MODES
63
+ * ============================================================================
64
+ * - OFF: Skip validation entirely
65
+ * - NEW_METHODS: Only validate in new methods (detected via git diff)
66
+ * - MODIFIED_AND_NEW_METHODS: Validate in new methods + methods with changes
67
+ * - MODIFIED_FILES: Validate all violations in modified files
68
+ * - ALL: Validate all violations in all TypeScript files
69
+ *
70
+ * ============================================================================
71
+ * ESCAPE HATCH
72
+ * ============================================================================
73
+ * Add comment above the violation:
74
+ * // webpieces-disable no-inline-types -- [your justification]
75
+ * function foo(arg: { x: number }) { }
76
+ *
77
+ * Use sparingly! Common valid reasons:
78
+ * - Prisma payload types that require inline generics
79
+ * - Third-party library APIs that expect inline types
80
+ * - Legacy code being incrementally migrated
81
+ */
82
+ import type { ExecutorContext } from '@nx/devkit';
83
+ export type NoInlineTypesMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';
84
+ export interface ValidateNoInlineTypesOptions {
85
+ mode?: NoInlineTypesMode;
86
+ }
87
+ export interface ExecutorResult {
88
+ success: boolean;
89
+ }
90
+ export default function runExecutor(options: ValidateNoInlineTypesOptions, context: ExecutorContext): Promise<ExecutorResult>;