@webpieces/dev-config 0.2.94 → 0.2.97

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.
Files changed (183) hide show
  1. package/config/eslint/base.mjs +1 -1
  2. package/executors.json +6 -91
  3. package/package.json +6 -19
  4. package/{executors → src/executors}/help/executor.d.ts +4 -2
  5. package/src/executors/help/executor.js.map +1 -0
  6. package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +3 -2
  7. package/src/executors/validate-eslint-sync/executor.js.map +1 -0
  8. package/{executors → src/executors}/validate-versions-locked/executor.js +5 -3
  9. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  10. package/src/generators/init/generator.js.map +1 -1
  11. package/src/index.d.ts +1 -1
  12. package/src/index.js +1 -1
  13. package/src/index.js.map +1 -1
  14. package/src/plugin.d.ts +86 -0
  15. package/{plugin.js → src/plugin.js} +31 -15
  16. package/src/plugin.js.map +1 -0
  17. package/src/toError.d.ts +5 -0
  18. package/src/toError.js +37 -0
  19. package/src/toError.js.map +1 -0
  20. package/templates/eslint.webpieces.config.mjs +1 -1
  21. package/templates/webpieces.exceptions.md +15 -15
  22. package/architecture/executors/diff-utils.d.ts +0 -24
  23. package/architecture/executors/diff-utils.js +0 -119
  24. package/architecture/executors/diff-utils.js.map +0 -1
  25. package/architecture/executors/diff-utils.ts +0 -127
  26. package/architecture/executors/generate/executor.d.ts +0 -16
  27. package/architecture/executors/generate/executor.js +0 -44
  28. package/architecture/executors/generate/executor.js.map +0 -1
  29. package/architecture/executors/generate/executor.ts +0 -59
  30. package/architecture/executors/generate/schema.json +0 -14
  31. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
  32. package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
  33. package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
  34. package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
  35. package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
  36. package/architecture/executors/validate-code/executor.d.ts +0 -78
  37. package/architecture/executors/validate-code/executor.js +0 -243
  38. package/architecture/executors/validate-code/executor.js.map +0 -1
  39. package/architecture/executors/validate-code/executor.ts +0 -406
  40. package/architecture/executors/validate-code/schema.json +0 -227
  41. package/architecture/executors/validate-dtos/executor.d.ts +0 -42
  42. package/architecture/executors/validate-dtos/executor.js +0 -561
  43. package/architecture/executors/validate-dtos/executor.js.map +0 -1
  44. package/architecture/executors/validate-dtos/executor.ts +0 -689
  45. package/architecture/executors/validate-dtos/schema.json +0 -33
  46. package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
  47. package/architecture/executors/validate-modified-files/executor.js +0 -501
  48. package/architecture/executors/validate-modified-files/executor.js.map +0 -1
  49. package/architecture/executors/validate-modified-files/executor.ts +0 -571
  50. package/architecture/executors/validate-modified-files/schema.json +0 -25
  51. package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
  52. package/architecture/executors/validate-modified-methods/executor.js +0 -694
  53. package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
  54. package/architecture/executors/validate-modified-methods/executor.ts +0 -797
  55. package/architecture/executors/validate-modified-methods/schema.json +0 -25
  56. package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
  57. package/architecture/executors/validate-new-methods/executor.js +0 -513
  58. package/architecture/executors/validate-new-methods/executor.js.map +0 -1
  59. package/architecture/executors/validate-new-methods/executor.ts +0 -584
  60. package/architecture/executors/validate-new-methods/schema.json +0 -25
  61. package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
  62. package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
  63. package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
  64. package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
  65. package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
  66. package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
  67. package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
  68. package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
  69. package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
  70. package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
  71. package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
  72. package/architecture/executors/validate-no-destructure/executor.js +0 -491
  73. package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
  74. package/architecture/executors/validate-no-destructure/executor.ts +0 -578
  75. package/architecture/executors/validate-no-destructure/schema.json +0 -24
  76. package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
  77. package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
  78. package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
  79. package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
  80. package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
  81. package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
  82. package/architecture/executors/validate-no-inline-types/executor.js +0 -669
  83. package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
  84. package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
  85. package/architecture/executors/validate-no-inline-types/schema.json +0 -24
  86. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
  87. package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
  88. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
  89. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
  90. package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
  91. package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
  92. package/architecture/executors/validate-packagejson/executor.js +0 -57
  93. package/architecture/executors/validate-packagejson/executor.js.map +0 -1
  94. package/architecture/executors/validate-packagejson/executor.ts +0 -74
  95. package/architecture/executors/validate-packagejson/schema.json +0 -8
  96. package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
  97. package/architecture/executors/validate-prisma-converters/executor.js +0 -634
  98. package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
  99. package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
  100. package/architecture/executors/validate-prisma-converters/schema.json +0 -38
  101. package/architecture/executors/validate-return-types/executor.d.ts +0 -29
  102. package/architecture/executors/validate-return-types/executor.js +0 -439
  103. package/architecture/executors/validate-return-types/executor.js.map +0 -1
  104. package/architecture/executors/validate-return-types/executor.ts +0 -524
  105. package/architecture/executors/validate-return-types/schema.json +0 -24
  106. package/architecture/executors/visualize/executor.d.ts +0 -17
  107. package/architecture/executors/visualize/executor.js +0 -49
  108. package/architecture/executors/visualize/executor.js.map +0 -1
  109. package/architecture/executors/visualize/executor.ts +0 -63
  110. package/architecture/executors/visualize/schema.json +0 -14
  111. package/architecture/index.d.ts +0 -19
  112. package/architecture/index.js +0 -23
  113. package/architecture/index.js.map +0 -1
  114. package/architecture/index.ts +0 -20
  115. package/architecture/lib/graph-comparator.d.ts +0 -39
  116. package/architecture/lib/graph-comparator.js +0 -100
  117. package/architecture/lib/graph-comparator.js.map +0 -1
  118. package/architecture/lib/graph-comparator.ts +0 -141
  119. package/architecture/lib/graph-generator.d.ts +0 -19
  120. package/architecture/lib/graph-generator.js +0 -84
  121. package/architecture/lib/graph-generator.js.map +0 -1
  122. package/architecture/lib/graph-generator.ts +0 -97
  123. package/architecture/lib/graph-loader.d.ts +0 -31
  124. package/architecture/lib/graph-loader.js +0 -98
  125. package/architecture/lib/graph-loader.js.map +0 -1
  126. package/architecture/lib/graph-loader.ts +0 -116
  127. package/architecture/lib/graph-sorter.d.ts +0 -37
  128. package/architecture/lib/graph-sorter.js +0 -110
  129. package/architecture/lib/graph-sorter.js.map +0 -1
  130. package/architecture/lib/graph-sorter.ts +0 -137
  131. package/architecture/lib/graph-visualizer.d.ts +0 -29
  132. package/architecture/lib/graph-visualizer.js +0 -217
  133. package/architecture/lib/graph-visualizer.js.map +0 -1
  134. package/architecture/lib/graph-visualizer.ts +0 -231
  135. package/architecture/lib/package-validator.d.ts +0 -38
  136. package/architecture/lib/package-validator.js +0 -126
  137. package/architecture/lib/package-validator.js.map +0 -1
  138. package/architecture/lib/package-validator.ts +0 -170
  139. package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -359
  140. package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
  141. package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
  142. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
  143. package/eslint-plugin/index.d.ts +0 -23
  144. package/eslint-plugin/index.js +0 -30
  145. package/eslint-plugin/index.js.map +0 -1
  146. package/eslint-plugin/index.ts +0 -29
  147. package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
  148. package/eslint-plugin/rules/catch-error-pattern.js +0 -196
  149. package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
  150. package/eslint-plugin/rules/catch-error-pattern.ts +0 -281
  151. package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
  152. package/eslint-plugin/rules/enforce-architecture.js +0 -476
  153. package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
  154. package/eslint-plugin/rules/enforce-architecture.ts +0 -543
  155. package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
  156. package/eslint-plugin/rules/max-file-lines.js +0 -257
  157. package/eslint-plugin/rules/max-file-lines.js.map +0 -1
  158. package/eslint-plugin/rules/max-file-lines.ts +0 -272
  159. package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
  160. package/eslint-plugin/rules/max-method-lines.js +0 -240
  161. package/eslint-plugin/rules/max-method-lines.js.map +0 -1
  162. package/eslint-plugin/rules/max-method-lines.ts +0 -287
  163. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
  164. package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
  165. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
  166. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
  167. package/executors/help/executor.js.map +0 -1
  168. package/executors/help/executor.ts +0 -61
  169. package/executors/validate-eslint-sync/executor.js.map +0 -1
  170. package/executors/validate-eslint-sync/executor.ts +0 -83
  171. package/executors/validate-versions-locked/executor.js.map +0 -1
  172. package/executors/validate-versions-locked/executor.ts +0 -367
  173. package/plugin/README.md +0 -243
  174. package/plugin/index.d.ts +0 -4
  175. package/plugin/index.js +0 -8
  176. package/plugin/index.js.map +0 -1
  177. package/plugin/index.ts +0 -4
  178. /package/{executors → src/executors}/help/executor.js +0 -0
  179. /package/{executors → src/executors}/help/schema.json +0 -0
  180. /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
  181. /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
  182. /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
  183. /package/{executors → src/executors}/validate-versions-locked/schema.json +0 -0
@@ -1,33 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "title": "Validate DTOs Executor",
4
- "description": "Validate DTO fields match Prisma Dbo model fields. Ensures AI agents don't invent field names.",
5
- "type": "object",
6
- "properties": {
7
- "mode": {
8
- "type": "string",
9
- "enum": ["OFF", "MODIFIED_CLASS", "MODIFIED_FILES"],
10
- "description": "OFF: skip validation. MODIFIED_CLASS: only validate Dto classes with changed lines. MODIFIED_FILES: validate all Dtos in modified files.",
11
- "default": "OFF"
12
- },
13
- "prismaSchemaPath": {
14
- "type": "string",
15
- "description": "Relative path from workspace root to schema.prisma"
16
- },
17
- "dtoSourcePaths": {
18
- "type": "array",
19
- "items": { "type": "string" },
20
- "description": "Array of directories (relative to workspace root) containing Dto files"
21
- },
22
- "disableAllowed": {
23
- "type": "boolean",
24
- "description": "Whether @deprecated field exemption works. When false, all fields must match.",
25
- "default": true
26
- },
27
- "ignoreModifiedUntilEpoch": {
28
- "type": "number",
29
- "description": "Epoch seconds. Until this time, skip DTO validation entirely. When expired, normal mode resumes. Omit when not needed."
30
- }
31
- },
32
- "required": []
33
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Validate Modified Files Executor
3
- *
4
- * Validates that modified files don't exceed a maximum line count (default 900).
5
- * This encourages keeping files small and focused - when you touch a file,
6
- * you must bring it under the limit.
7
- *
8
- * Usage:
9
- * nx affected --target=validate-modified-files --base=origin/main
10
- *
11
- * Escape hatch: Add webpieces-disable max-lines-modified-files comment with date and justification
12
- * Format: // webpieces-disable max-lines-modified-files 2025/01/15 -- [reason]
13
- * The disable expires after 1 month from the date specified.
14
- */
15
- import type { ExecutorContext } from '@nx/devkit';
16
- export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
17
- export interface ValidateModifiedFilesOptions {
18
- limit?: number;
19
- mode?: FileMaxLimitMode;
20
- disableAllowed?: boolean;
21
- }
22
- export interface ExecutorResult {
23
- success: boolean;
24
- }
25
- export default function runExecutor(options: ValidateModifiedFilesOptions, context: ExecutorContext): Promise<ExecutorResult>;
@@ -1,501 +0,0 @@
1
- "use strict";
2
- /**
3
- * Validate Modified Files Executor
4
- *
5
- * Validates that modified files don't exceed a maximum line count (default 900).
6
- * This encourages keeping files small and focused - when you touch a file,
7
- * you must bring it under the limit.
8
- *
9
- * Usage:
10
- * nx affected --target=validate-modified-files --base=origin/main
11
- *
12
- * Escape hatch: Add webpieces-disable max-lines-modified-files comment with date and justification
13
- * Format: // webpieces-disable max-lines-modified-files 2025/01/15 -- [reason]
14
- * The disable expires after 1 month from the date specified.
15
- */
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = runExecutor;
18
- const tslib_1 = require("tslib");
19
- const child_process_1 = require("child_process");
20
- const fs = tslib_1.__importStar(require("fs"));
21
- const path = tslib_1.__importStar(require("path"));
22
- const TMP_DIR = 'tmp/webpieces';
23
- const TMP_MD_FILE = 'webpieces.filesize.md';
24
- const FILESIZE_DOC_CONTENT = `# AI Agent Instructions: File Too Long
25
-
26
- **READ THIS FILE to fix files that are too long**
27
-
28
- ## Core Principle
29
-
30
- With **stateless systems + dependency injection, refactor is trivial**.
31
- Pick a method or a few and move to new class XXXXX, then inject XXXXX
32
- into all users of those methods via the constructor.
33
- Delete those methods from original class.
34
-
35
- **99% of files can be less than the configured max lines of code.**
36
-
37
- Files should contain a SINGLE COHESIVE UNIT.
38
- - One class per file (Java convention)
39
- - If class is too large, extract child responsibilities
40
- - Use dependency injection to compose functionality
41
-
42
- ## Command: Reduce File Size
43
-
44
- ### Step 1: Check for Multiple Classes
45
- If the file contains multiple classes, **SEPARATE each class into its own file**.
46
-
47
- \`\`\`typescript
48
- // BAD: UserController.ts (multiple classes)
49
- export class UserController { /* ... */ }
50
- export class UserValidator { /* ... */ }
51
- export class UserNotifier { /* ... */ }
52
-
53
- // GOOD: Three separate files
54
- // UserController.ts
55
- export class UserController { /* ... */ }
56
-
57
- // UserValidator.ts
58
- export class UserValidator { /* ... */ }
59
-
60
- // UserNotifier.ts
61
- export class UserNotifier { /* ... */ }
62
- \`\`\`
63
-
64
- ### Step 2: Extract Child Responsibilities (if single class is too large)
65
-
66
- #### Pattern: Create New Service Class with Dependency Injection
67
-
68
- \`\`\`typescript
69
- // BAD: UserController.ts (800 lines, single class)
70
- @provideSingleton()
71
- @Controller()
72
- export class UserController {
73
- // 200 lines: CRUD operations
74
- // 300 lines: validation logic
75
- // 200 lines: notification logic
76
- // 100 lines: analytics logic
77
- }
78
-
79
- // GOOD: Extract validation service
80
- // 1. Create UserValidationService.ts
81
- @provideSingleton()
82
- export class UserValidationService {
83
- validateUserData(data: UserData): ValidationResult {
84
- // 300 lines of validation logic moved here
85
- }
86
-
87
- validateEmail(email: string): boolean { /* ... */ }
88
- validatePassword(password: string): boolean { /* ... */ }
89
- }
90
-
91
- // 2. Inject into UserController.ts
92
- @provideSingleton()
93
- @Controller()
94
- export class UserController {
95
- constructor(
96
- @inject(TYPES.UserValidationService)
97
- private validator: UserValidationService
98
- ) {}
99
-
100
- async createUser(data: UserData): Promise<User> {
101
- const validation = this.validator.validateUserData(data);
102
- if (!validation.isValid) {
103
- throw new ValidationError(validation.errors);
104
- }
105
- // ... rest of logic
106
- }
107
- }
108
- \`\`\`
109
-
110
- ## AI Agent Action Steps
111
-
112
- 1. **ANALYZE** the file structure:
113
- - Count classes (if >1, separate immediately)
114
- - Identify logical responsibilities within single class
115
-
116
- 2. **IDENTIFY** "child code" to extract:
117
- - Validation logic -> ValidationService
118
- - Notification logic -> NotificationService
119
- - Data transformation -> TransformerService
120
- - External API calls -> ApiService
121
- - Business rules -> RulesEngine
122
-
123
- 3. **CREATE** new service file(s):
124
- - Start with temporary name: \`XXXX.ts\` or \`ChildService.ts\`
125
- - Add \`@provideSingleton()\` decorator
126
- - Move child methods to new class
127
-
128
- 4. **UPDATE** dependency injection:
129
- - Add to \`TYPES\` constants (if using symbol-based DI)
130
- - Inject new service into original class constructor
131
- - Replace direct method calls with \`this.serviceName.method()\`
132
-
133
- 5. **RENAME** extracted file:
134
- - Read the extracted code to understand its purpose
135
- - Rename \`XXXX.ts\` to logical name (e.g., \`UserValidationService.ts\`)
136
-
137
- 6. **VERIFY** file sizes:
138
- - Original file should now be under the limit
139
- - Each extracted file should be under the limit
140
- - If still too large, extract more services
141
-
142
- ## Examples of Child Responsibilities to Extract
143
-
144
- | If File Contains | Extract To | Pattern |
145
- |-----------------|------------|---------|
146
- | Validation logic (200+ lines) | \`XValidator.ts\` or \`XValidationService.ts\` | Singleton service |
147
- | Notification logic (150+ lines) | \`XNotifier.ts\` or \`XNotificationService.ts\` | Singleton service |
148
- | Data transformation (200+ lines) | \`XTransformer.ts\` | Singleton service |
149
- | External API calls (200+ lines) | \`XApiClient.ts\` | Singleton service |
150
- | Complex business rules (300+ lines) | \`XRulesEngine.ts\` | Singleton service |
151
- | Database queries (200+ lines) | \`XRepository.ts\` | Singleton service |
152
-
153
- ## WebPieces Dependency Injection Pattern
154
-
155
- \`\`\`typescript
156
- // 1. Define service with @provideSingleton
157
- import { provideSingleton } from '@webpieces/http-routing';
158
-
159
- @provideSingleton()
160
- export class MyService {
161
- doSomething(): void { /* ... */ }
162
- }
163
-
164
- // 2. Inject into consumer
165
- import { inject } from 'inversify';
166
- import { TYPES } from './types';
167
-
168
- @provideSingleton()
169
- @Controller()
170
- export class MyController {
171
- constructor(
172
- @inject(TYPES.MyService) private service: MyService
173
- ) {}
174
- }
175
- \`\`\`
176
-
177
- ## Escape Hatch
178
-
179
- If refactoring is genuinely not feasible (generated files, complex algorithms, etc.),
180
- add a disable comment at the TOP of the file (within first 5 lines) with a DATE:
181
-
182
- \`\`\`typescript
183
- // webpieces-disable max-lines-modified-files 2025/01/15 -- Complex generated file, refactoring would break generation
184
- \`\`\`
185
-
186
- **IMPORTANT**: The date format is yyyy/mm/dd. The disable will EXPIRE after 1 month from this date.
187
- After expiration, you must either fix the file or update the date to get another month.
188
- This ensures that disable comments are reviewed periodically.
189
-
190
- Remember: Find the "child code" and pull it down into a new class. Once moved, the code's purpose becomes clear, making it easy to rename to a logical name.
191
- `;
192
- /**
193
- * Write the instructions documentation to tmp directory
194
- */
195
- function writeTmpInstructions(workspaceRoot) {
196
- const tmpDir = path.join(workspaceRoot, TMP_DIR);
197
- const mdPath = path.join(tmpDir, TMP_MD_FILE);
198
- fs.mkdirSync(tmpDir, { recursive: true });
199
- fs.writeFileSync(mdPath, FILESIZE_DOC_CONTENT);
200
- return mdPath;
201
- }
202
- /**
203
- * Get changed TypeScript files between base and head (or working tree if head not specified).
204
- * Uses `git diff base [head]` to match what `nx affected` does.
205
- * When head is NOT specified, also includes untracked files (matching nx affected behavior).
206
- */
207
- function getChangedTypeScriptFiles(workspaceRoot, base, head) {
208
- try {
209
- // If head is specified, diff base to head; otherwise diff base to working tree
210
- const diffTarget = head ? `${base} ${head}` : base;
211
- const output = (0, child_process_1.execSync)(`git diff --name-only ${diffTarget} -- '*.ts' '*.tsx'`, {
212
- cwd: workspaceRoot,
213
- encoding: 'utf-8',
214
- });
215
- const changedFiles = output
216
- .trim()
217
- .split('\n')
218
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
219
- // When comparing to working tree (no head specified), also include untracked files
220
- // This matches what nx affected does: "All modified files not yet committed or tracked will also be added"
221
- if (!head) {
222
- try {
223
- const untrackedOutput = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard '*.ts' '*.tsx'`, {
224
- cwd: workspaceRoot,
225
- encoding: 'utf-8',
226
- });
227
- const untrackedFiles = untrackedOutput
228
- .trim()
229
- .split('\n')
230
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
231
- // Merge and dedupe
232
- const allFiles = new Set([...changedFiles, ...untrackedFiles]);
233
- return Array.from(allFiles);
234
- }
235
- catch {
236
- // If ls-files fails, just return the changed files
237
- return changedFiles;
238
- }
239
- }
240
- return changedFiles;
241
- }
242
- catch {
243
- return [];
244
- }
245
- }
246
- /**
247
- * Parse a date string in yyyy/mm/dd format and return a Date object.
248
- * Returns null if the format is invalid.
249
- */
250
- function parseDisableDate(dateStr) {
251
- // Match yyyy/mm/dd format
252
- const match = dateStr.match(/^(\d{4})\/(\d{2})\/(\d{2})$/);
253
- if (!match)
254
- return null;
255
- const year = parseInt(match[1], 10);
256
- const month = parseInt(match[2], 10) - 1; // JS months are 0-indexed
257
- const day = parseInt(match[3], 10);
258
- const date = new Date(year, month, day);
259
- // Validate the date is valid (e.g., not Feb 30)
260
- if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {
261
- return null;
262
- }
263
- return date;
264
- }
265
- /**
266
- * Check if a date is within the last month (not expired).
267
- */
268
- function isDateWithinMonth(date) {
269
- const now = new Date();
270
- const oneMonthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
271
- return date >= oneMonthAgo;
272
- }
273
- /**
274
- * Check if a file has a valid, non-expired disable comment at the top (within first 5 lines).
275
- * Returns status object with details about the disable comment.
276
- */
277
- // webpieces-disable max-lines-new-methods -- Date validation logic requires checking multiple conditions
278
- function checkDisableComment(content) {
279
- const lines = content.split('\n').slice(0, 5);
280
- for (const line of lines) {
281
- if (line.includes('webpieces-disable') && line.includes('max-lines-modified-files')) {
282
- // Found disable comment, now check for date
283
- // Format: // webpieces-disable max-lines-modified-files yyyy/mm/dd -- reason
284
- const dateMatch = line.match(/max-lines-modified-files\s+(\d{4}\/\d{2}\/\d{2}|XXXX\/XX\/XX)/);
285
- if (!dateMatch) {
286
- // No date found - invalid disable comment
287
- return { hasDisable: true, isValid: false, isExpired: false };
288
- }
289
- const dateStr = dateMatch[1];
290
- // Secret permanent disable
291
- if (dateStr === 'XXXX/XX/XX') {
292
- return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };
293
- }
294
- const date = parseDisableDate(dateStr);
295
- if (!date) {
296
- // Invalid date format
297
- return { hasDisable: true, isValid: false, isExpired: false, date: dateStr };
298
- }
299
- if (!isDateWithinMonth(date)) {
300
- // Date is expired (older than 1 month)
301
- return { hasDisable: true, isValid: true, isExpired: true, date: dateStr };
302
- }
303
- // Valid and not expired
304
- return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };
305
- }
306
- }
307
- return { hasDisable: false, isValid: false, isExpired: false };
308
- }
309
- /**
310
- * Count lines in a file and check for violations
311
- */
312
- // webpieces-disable max-lines-new-methods -- File iteration with disable checking logic
313
- function findViolations(workspaceRoot, changedFiles, limit, disableAllowed) {
314
- const violations = [];
315
- for (const file of changedFiles) {
316
- const fullPath = path.join(workspaceRoot, file);
317
- if (!fs.existsSync(fullPath))
318
- continue;
319
- const content = fs.readFileSync(fullPath, 'utf-8');
320
- const lineCount = content.split('\n').length;
321
- // Skip files under the limit
322
- if (lineCount <= limit)
323
- continue;
324
- // When disableAllowed is false, ignore all disable comments
325
- if (!disableAllowed) {
326
- violations.push({ file, lines: lineCount });
327
- continue;
328
- }
329
- // Check for disable comment
330
- const disableStatus = checkDisableComment(content);
331
- if (disableStatus.hasDisable) {
332
- if (disableStatus.isValid && !disableStatus.isExpired) {
333
- // Valid, non-expired disable - skip this file
334
- continue;
335
- }
336
- if (disableStatus.isExpired) {
337
- // Expired disable - report as violation with expired info
338
- violations.push({
339
- file,
340
- lines: lineCount,
341
- expiredDisable: true,
342
- expiredDate: disableStatus.date,
343
- });
344
- continue;
345
- }
346
- // Invalid disable (missing/bad date) - fall through to report as violation
347
- }
348
- violations.push({
349
- file,
350
- lines: lineCount,
351
- });
352
- }
353
- return violations;
354
- }
355
- /**
356
- * Auto-detect the base branch by finding the merge-base with origin/main.
357
- */
358
- function detectBase(workspaceRoot) {
359
- try {
360
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD origin/main', {
361
- cwd: workspaceRoot,
362
- encoding: 'utf-8',
363
- stdio: ['pipe', 'pipe', 'pipe'],
364
- }).trim();
365
- if (mergeBase) {
366
- return mergeBase;
367
- }
368
- }
369
- catch {
370
- try {
371
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD main', {
372
- cwd: workspaceRoot,
373
- encoding: 'utf-8',
374
- stdio: ['pipe', 'pipe', 'pipe'],
375
- }).trim();
376
- if (mergeBase) {
377
- return mergeBase;
378
- }
379
- }
380
- catch {
381
- // Ignore
382
- }
383
- }
384
- return null;
385
- }
386
- /**
387
- * Get today's date in yyyy/mm/dd format for error messages
388
- */
389
- function getTodayDateString() {
390
- const now = new Date();
391
- const year = now.getFullYear();
392
- const month = String(now.getMonth() + 1).padStart(2, '0');
393
- const day = String(now.getDate()).padStart(2, '0');
394
- return `${year}/${month}/${day}`;
395
- }
396
- /**
397
- * Report violations to console
398
- */
399
- // webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections
400
- function reportViolations(violations, limit, disableAllowed) {
401
- console.error('');
402
- console.error('\u274c YOU MUST FIX THIS AND NOT be more than ' + limit + ' lines of code per file');
403
- console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');
404
- console.error('');
405
- console.error('\ud83d\udcda With stateless systems + dependency injection, refactor is trivial:');
406
- console.error(' Pick a method or a few and move to new class XXXXX, then inject XXXXX');
407
- console.error(' into all users of those methods via the constructor.');
408
- console.error(' Delete those methods from original class.');
409
- console.error(' 99% of files can be less than ' + limit + ' lines of code.');
410
- console.error('');
411
- console.error('\u26a0\ufe0f *** READ tmp/webpieces/webpieces.filesize.md for detailed guidance on how to fix this easily *** \u26a0\ufe0f');
412
- console.error('');
413
- for (const v of violations) {
414
- if (v.expiredDisable) {
415
- console.error(` \u274c ${v.file} (${v.lines} lines, max: ${limit})`);
416
- console.error(` \u23f0 EXPIRED DISABLE: Your disable comment dated ${v.expiredDate} has expired (>1 month old).`);
417
- console.error(` You must either FIX the file or UPDATE the date to get another month.`);
418
- }
419
- else {
420
- console.error(` \u274c ${v.file} (${v.lines} lines, max: ${limit})`);
421
- }
422
- }
423
- console.error('');
424
- // Only show escape hatch instructions when disableAllowed is true
425
- if (disableAllowed) {
426
- console.error(' You can disable this error, but you will be forced to fix again in 1 month');
427
- console.error(' since 99% of files can be less than ' + limit + ' lines of code.');
428
- console.error('');
429
- console.error(' Use escape with DATE (expires in 1 month):');
430
- console.error(` // webpieces-disable max-lines-modified-files ${getTodayDateString()} -- [your reason]`);
431
- console.error('');
432
- }
433
- else {
434
- console.error(' \u26a0\ufe0f disableAllowed is false - disable comments are NOT allowed.');
435
- console.error(' This rule must be met and cannot be disabled since nx.json disableAllowed is set to false.');
436
- console.error(' You MUST refactor to reduce file size.');
437
- console.error('');
438
- console.error(' For a major refactor, a human can add "ignoreModifiedUntilEpoch" to nx.json validate-code options.');
439
- console.error(' This is an expiry timestamp (epoch ms) for when we start forcing everyone to meet size rules again.');
440
- console.error(' Sometimes for speed, we allow files to expand during a refactor and over time,');
441
- console.error(' each PR reduces files as they get touched.');
442
- console.error(' AI agents should NOT add ignoreModifiedUntilEpoch - ask a human to do it.');
443
- console.error('');
444
- }
445
- }
446
- async function runExecutor(options, context) {
447
- const workspaceRoot = context.root;
448
- const limit = options.limit ?? 900;
449
- const mode = options.mode ?? 'MODIFIED_FILES';
450
- const disableAllowed = options.disableAllowed ?? true;
451
- // Skip validation entirely if mode is OFF
452
- if (mode === 'OFF') {
453
- console.log('\n\u23ed\ufe0f Skipping modified files validation (mode: OFF)');
454
- console.log('');
455
- return { success: true };
456
- }
457
- // If NX_HEAD is set (via nx affected --head=X), use it; otherwise compare to working tree
458
- let base = process.env['NX_BASE'];
459
- const head = process.env['NX_HEAD'];
460
- if (!base) {
461
- base = detectBase(workspaceRoot) ?? undefined;
462
- if (!base) {
463
- console.log('\n\u23ed\ufe0f Skipping modified files validation (could not detect base branch)');
464
- console.log(' To run explicitly: nx affected --target=validate-modified-files --base=origin/main');
465
- console.log('');
466
- return { success: true };
467
- }
468
- console.log('\n\ud83d\udccf Validating Modified File Sizes (auto-detected base)\n');
469
- }
470
- else {
471
- console.log('\n\ud83d\udccf Validating Modified File Sizes\n');
472
- }
473
- console.log(` Base: ${base}`);
474
- console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
475
- console.log(` Mode: ${mode}`);
476
- console.log(` Max lines for modified files: ${limit}`);
477
- console.log(` Disable allowed: ${disableAllowed}${!disableAllowed ? ' (no escape hatch)' : ''}`);
478
- console.log('');
479
- try {
480
- const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);
481
- if (changedFiles.length === 0) {
482
- console.log('\u2705 No TypeScript files changed');
483
- return { success: true };
484
- }
485
- console.log(`\ud83d\udcc2 Checking ${changedFiles.length} changed file(s)...`);
486
- const violations = findViolations(workspaceRoot, changedFiles, limit, disableAllowed);
487
- if (violations.length === 0) {
488
- console.log('\u2705 All modified files are under ' + limit + ' lines');
489
- return { success: true };
490
- }
491
- writeTmpInstructions(workspaceRoot);
492
- reportViolations(violations, limit, disableAllowed);
493
- return { success: false };
494
- }
495
- catch (err) {
496
- const error = err instanceof Error ? err : new Error(String(err));
497
- console.error('\u274c Modified files validation failed:', error.message);
498
- return { success: false };
499
- }
500
- }
501
- //# sourceMappingURL=executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-modified-files/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AA0eH,8BAmEC;;AA1i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AAC;IAEhB,IAAI,CAAC;QACD,MAAM,YAAY,GAAG,yBAAyB,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAE1E,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;YAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,yBAAyB,YAAY,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAE/E,MAAM,UAAU,GAAG,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;QAEtF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,sCAAsC,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC;YACvE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACpC,gBAAgB,CAAC,UAAU,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;QACpD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACzE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Modified Files Executor\n *\n * Validates that modified files don't exceed a maximum line count (default 900).\n * This encourages keeping files small and focused - when you touch a file,\n * you must bring it under the limit.\n *\n * Usage:\n * nx affected --target=validate-modified-files --base=origin/main\n *\n * Escape hatch: Add webpieces-disable max-lines-modified-files comment with date and justification\n * Format: // webpieces-disable max-lines-modified-files 2025/01/15 -- [reason]\n * The disable expires after 1 month from the date specified.\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';\n\nexport interface ValidateModifiedFilesOptions {\n limit?: number;\n mode?: FileMaxLimitMode;\n disableAllowed?: boolean;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface FileViolation {\n file: string;\n lines: number;\n expiredDisable?: boolean;\n expiredDate?: string;\n}\n\nconst TMP_DIR = 'tmp/webpieces';\nconst TMP_MD_FILE = 'webpieces.filesize.md';\n\nconst FILESIZE_DOC_CONTENT = `# AI Agent Instructions: File Too Long\n\n**READ THIS FILE to fix files that are too long**\n\n## Core Principle\n\nWith **stateless systems + dependency injection, refactor is trivial**.\nPick a method or a few and move to new class XXXXX, then inject XXXXX\ninto all users of those methods via the constructor.\nDelete those methods from original class.\n\n**99% of files can be less than the configured max lines of code.**\n\nFiles should contain a SINGLE COHESIVE UNIT.\n- One class per file (Java convention)\n- If class is too large, extract child responsibilities\n- Use dependency injection to compose functionality\n\n## Command: Reduce File Size\n\n### Step 1: Check for Multiple Classes\nIf the file contains multiple classes, **SEPARATE each class into its own file**.\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (multiple classes)\nexport class UserController { /* ... */ }\nexport class UserValidator { /* ... */ }\nexport class UserNotifier { /* ... */ }\n\n// GOOD: Three separate files\n// UserController.ts\nexport class UserController { /* ... */ }\n\n// UserValidator.ts\nexport class UserValidator { /* ... */ }\n\n// UserNotifier.ts\nexport class UserNotifier { /* ... */ }\n\\`\\`\\`\n\n### Step 2: Extract Child Responsibilities (if single class is too large)\n\n#### Pattern: Create New Service Class with Dependency Injection\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (800 lines, single class)\n@provideSingleton()\n@Controller()\nexport class UserController {\n // 200 lines: CRUD operations\n // 300 lines: validation logic\n // 200 lines: notification logic\n // 100 lines: analytics logic\n}\n\n// GOOD: Extract validation service\n// 1. Create UserValidationService.ts\n@provideSingleton()\nexport class UserValidationService {\n validateUserData(data: UserData): ValidationResult {\n // 300 lines of validation logic moved here\n }\n\n validateEmail(email: string): boolean { /* ... */ }\n validatePassword(password: string): boolean { /* ... */ }\n}\n\n// 2. Inject into UserController.ts\n@provideSingleton()\n@Controller()\nexport class UserController {\n constructor(\n @inject(TYPES.UserValidationService)\n private validator: UserValidationService\n ) {}\n\n async createUser(data: UserData): Promise<User> {\n const validation = this.validator.validateUserData(data);\n if (!validation.isValid) {\n throw new ValidationError(validation.errors);\n }\n // ... rest of logic\n }\n}\n\\`\\`\\`\n\n## AI Agent Action Steps\n\n1. **ANALYZE** the file structure:\n - Count classes (if >1, separate immediately)\n - Identify logical responsibilities within single class\n\n2. **IDENTIFY** \"child code\" to extract:\n - Validation logic -> ValidationService\n - Notification logic -> NotificationService\n - Data transformation -> TransformerService\n - External API calls -> ApiService\n - Business rules -> RulesEngine\n\n3. **CREATE** new service file(s):\n - Start with temporary name: \\`XXXX.ts\\` or \\`ChildService.ts\\`\n - Add \\`@provideSingleton()\\` decorator\n - Move child methods to new class\n\n4. **UPDATE** dependency injection:\n - Add to \\`TYPES\\` constants (if using symbol-based DI)\n - Inject new service into original class constructor\n - Replace direct method calls with \\`this.serviceName.method()\\`\n\n5. **RENAME** extracted file:\n - Read the extracted code to understand its purpose\n - Rename \\`XXXX.ts\\` to logical name (e.g., \\`UserValidationService.ts\\`)\n\n6. **VERIFY** file sizes:\n - Original file should now be under the limit\n - Each extracted file should be under the limit\n - If still too large, extract more services\n\n## Examples of Child Responsibilities to Extract\n\n| If File Contains | Extract To | Pattern |\n|-----------------|------------|---------|\n| Validation logic (200+ lines) | \\`XValidator.ts\\` or \\`XValidationService.ts\\` | Singleton service |\n| Notification logic (150+ lines) | \\`XNotifier.ts\\` or \\`XNotificationService.ts\\` | Singleton service |\n| Data transformation (200+ lines) | \\`XTransformer.ts\\` | Singleton service |\n| External API calls (200+ lines) | \\`XApiClient.ts\\` | Singleton service |\n| Complex business rules (300+ lines) | \\`XRulesEngine.ts\\` | Singleton service |\n| Database queries (200+ lines) | \\`XRepository.ts\\` | Singleton service |\n\n## WebPieces Dependency Injection Pattern\n\n\\`\\`\\`typescript\n// 1. Define service with @provideSingleton\nimport { provideSingleton } from '@webpieces/http-routing';\n\n@provideSingleton()\nexport class MyService {\n doSomething(): void { /* ... */ }\n}\n\n// 2. Inject into consumer\nimport { inject } from 'inversify';\nimport { TYPES } from './types';\n\n@provideSingleton()\n@Controller()\nexport class MyController {\n constructor(\n @inject(TYPES.MyService) private service: MyService\n ) {}\n}\n\\`\\`\\`\n\n## Escape Hatch\n\nIf refactoring is genuinely not feasible (generated files, complex algorithms, etc.),\nadd a disable comment at the TOP of the file (within first 5 lines) with a DATE:\n\n\\`\\`\\`typescript\n// webpieces-disable max-lines-modified-files 2025/01/15 -- Complex generated file, refactoring would break generation\n\\`\\`\\`\n\n**IMPORTANT**: The date format is yyyy/mm/dd. The disable will EXPIRE after 1 month from this date.\nAfter expiration, you must either fix the file or update the date to get another month.\nThis ensures that disable comments are reviewed periodically.\n\nRemember: Find the \"child code\" and pull it down into a new class. Once moved, the code's purpose becomes clear, making it easy to rename to a logical name.\n`;\n\n/**\n * Write the instructions documentation to tmp directory\n */\nfunction writeTmpInstructions(workspaceRoot: string): string {\n const tmpDir = path.join(workspaceRoot, TMP_DIR);\n const mdPath = path.join(tmpDir, TMP_MD_FILE);\n\n fs.mkdirSync(tmpDir, { recursive: true });\n fs.writeFileSync(mdPath, FILESIZE_DOC_CONTENT);\n\n return mdPath;\n}\n\n/**\n * Get changed TypeScript files between base and head (or working tree if head not specified).\n * Uses `git diff base [head]` to match what `nx affected` does.\n * When head is NOT specified, also includes untracked files (matching nx affected behavior).\n */\nfunction getChangedTypeScriptFiles(workspaceRoot: string, base: string, head?: string): string[] {\n try {\n // If head is specified, diff base to head; otherwise diff base to working tree\n const diffTarget = head ? `${base} ${head}` : base;\n const output = execSync(`git diff --name-only ${diffTarget} -- '*.ts' '*.tsx'`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const changedFiles = output\n .trim()\n .split('\\n')\n .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));\n\n // When comparing to working tree (no head specified), also include untracked files\n // This matches what nx affected does: \"All modified files not yet committed or tracked will also be added\"\n if (!head) {\n try {\n const untrackedOutput = execSync(`git ls-files --others --exclude-standard '*.ts' '*.tsx'`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const untrackedFiles = untrackedOutput\n .trim()\n .split('\\n')\n .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));\n // Merge and dedupe\n const allFiles = new Set([...changedFiles, ...untrackedFiles]);\n return Array.from(allFiles);\n } catch {\n // If ls-files fails, just return the changed files\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch {\n return [];\n }\n}\n\n/**\n * Parse a date string in yyyy/mm/dd format and return a Date object.\n * Returns null if the format is invalid.\n */\nfunction parseDisableDate(dateStr: string): Date | null {\n // Match yyyy/mm/dd format\n const match = dateStr.match(/^(\\d{4})\\/(\\d{2})\\/(\\d{2})$/);\n if (!match) return null;\n\n const year = parseInt(match[1], 10);\n const month = parseInt(match[2], 10) - 1; // JS months are 0-indexed\n const day = parseInt(match[3], 10);\n\n const date = new Date(year, month, day);\n\n // Validate the date is valid (e.g., not Feb 30)\n if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {\n return null;\n }\n\n return date;\n}\n\n/**\n * Check if a date is within the last month (not expired).\n */\nfunction isDateWithinMonth(date: Date): boolean {\n const now = new Date();\n const oneMonthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());\n return date >= oneMonthAgo;\n}\n\ninterface DisableStatus {\n hasDisable: boolean;\n isValid: boolean;\n isExpired: boolean;\n date?: string;\n}\n\n/**\n * Check if a file has a valid, non-expired disable comment at the top (within first 5 lines).\n * Returns status object with details about the disable comment.\n */\n// webpieces-disable max-lines-new-methods -- Date validation logic requires checking multiple conditions\nfunction checkDisableComment(content: string): DisableStatus {\n const lines = content.split('\\n').slice(0, 5);\n\n for (const line of lines) {\n if (line.includes('webpieces-disable') && line.includes('max-lines-modified-files')) {\n // Found disable comment, now check for date\n // Format: // webpieces-disable max-lines-modified-files yyyy/mm/dd -- reason\n const dateMatch = line.match(/max-lines-modified-files\\s+(\\d{4}\\/\\d{2}\\/\\d{2}|XXXX\\/XX\\/XX)/);\n\n if (!dateMatch) {\n // No date found - invalid disable comment\n return { hasDisable: true, isValid: false, isExpired: false };\n }\n\n const dateStr = dateMatch[1];\n\n // Secret permanent disable\n if (dateStr === 'XXXX/XX/XX') {\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n\n const date = parseDisableDate(dateStr);\n if (!date) {\n // Invalid date format\n return { hasDisable: true, isValid: false, isExpired: false, date: dateStr };\n }\n\n if (!isDateWithinMonth(date)) {\n // Date is expired (older than 1 month)\n return { hasDisable: true, isValid: true, isExpired: true, date: dateStr };\n }\n\n // Valid and not expired\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n }\n\n return { hasDisable: false, isValid: false, isExpired: false };\n}\n\n/**\n * Count lines in a file and check for violations\n */\n// webpieces-disable max-lines-new-methods -- File iteration with disable checking logic\nfunction findViolations(workspaceRoot: string, changedFiles: string[], limit: number, disableAllowed: boolean): FileViolation[] {\n const violations: FileViolation[] = [];\n\n for (const file of changedFiles) {\n const fullPath = path.join(workspaceRoot, file);\n\n if (!fs.existsSync(fullPath)) continue;\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const lineCount = content.split('\\n').length;\n\n // Skip files under the limit\n if (lineCount <= limit) continue;\n\n // When disableAllowed is false, ignore all disable comments\n if (!disableAllowed) {\n violations.push({ file, lines: lineCount });\n continue;\n }\n\n // Check for disable comment\n const disableStatus = checkDisableComment(content);\n\n if (disableStatus.hasDisable) {\n if (disableStatus.isValid && !disableStatus.isExpired) {\n // Valid, non-expired disable - skip this file\n continue;\n }\n\n if (disableStatus.isExpired) {\n // Expired disable - report as violation with expired info\n violations.push({\n file,\n lines: lineCount,\n expiredDisable: true,\n expiredDate: disableStatus.date,\n });\n continue;\n }\n\n // Invalid disable (missing/bad date) - fall through to report as violation\n }\n\n violations.push({\n file,\n lines: lineCount,\n });\n }\n\n return violations;\n}\n\n/**\n * Auto-detect the base branch by finding the merge-base with origin/main.\n */\nfunction detectBase(workspaceRoot: string): string | null {\n try {\n const mergeBase = execSync('git merge-base HEAD origin/main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n try {\n const mergeBase = execSync('git merge-base HEAD main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n // Ignore\n }\n }\n return null;\n}\n\n/**\n * Get today's date in yyyy/mm/dd format for error messages\n */\nfunction getTodayDateString(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}/${month}/${day}`;\n}\n\n/**\n * Report violations to console\n */\n// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections\nfunction reportViolations(violations: FileViolation[], limit: number, disableAllowed: boolean): void {\n console.error('');\n console.error('\\u274c YOU MUST FIX THIS AND NOT be more than ' + limit + ' lines of code per file');\n console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');\n console.error('');\n console.error('\\ud83d\\udcda With stateless systems + dependency injection, refactor is trivial:');\n console.error(' Pick a method or a few and move to new class XXXXX, then inject XXXXX');\n console.error(' into all users of those methods via the constructor.');\n console.error(' Delete those methods from original class.');\n console.error(' 99% of files can be less than ' + limit + ' lines of code.');\n console.error('');\n console.error('\\u26a0\\ufe0f *** READ tmp/webpieces/webpieces.filesize.md for detailed guidance on how to fix this easily *** \\u26a0\\ufe0f');\n console.error('');\n\n for (const v of violations) {\n if (v.expiredDisable) {\n console.error(` \\u274c ${v.file} (${v.lines} lines, max: ${limit})`);\n console.error(` \\u23f0 EXPIRED DISABLE: Your disable comment dated ${v.expiredDate} has expired (>1 month old).`);\n console.error(` You must either FIX the file or UPDATE the date to get another month.`);\n } else {\n console.error(` \\u274c ${v.file} (${v.lines} lines, max: ${limit})`);\n }\n }\n console.error('');\n\n // Only show escape hatch instructions when disableAllowed is true\n if (disableAllowed) {\n console.error(' You can disable this error, but you will be forced to fix again in 1 month');\n console.error(' since 99% of files can be less than ' + limit + ' lines of code.');\n console.error('');\n console.error(' Use escape with DATE (expires in 1 month):');\n console.error(` // webpieces-disable max-lines-modified-files ${getTodayDateString()} -- [your reason]`);\n console.error('');\n } else {\n console.error(' \\u26a0\\ufe0f disableAllowed is false - disable comments are NOT allowed.');\n console.error(' This rule must be met and cannot be disabled since nx.json disableAllowed is set to false.');\n console.error(' You MUST refactor to reduce file size.');\n console.error('');\n console.error(' For a major refactor, a human can add \"ignoreModifiedUntilEpoch\" to nx.json validate-code options.');\n console.error(' This is an expiry timestamp (epoch ms) for when we start forcing everyone to meet size rules again.');\n console.error(' Sometimes for speed, we allow files to expand during a refactor and over time,');\n console.error(' each PR reduces files as they get touched.');\n console.error(' AI agents should NOT add ignoreModifiedUntilEpoch - ask a human to do it.');\n console.error('');\n }\n}\n\nexport default async function runExecutor(\n options: ValidateModifiedFilesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const limit = options.limit ?? 900;\n const mode: FileMaxLimitMode = options.mode ?? 'MODIFIED_FILES';\n const disableAllowed = options.disableAllowed ?? true;\n\n // Skip validation entirely if mode is OFF\n if (mode === 'OFF') {\n console.log('\\n\\u23ed\\ufe0f Skipping modified files validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n // If NX_HEAD is set (via nx affected --head=X), use it; otherwise compare to working tree\n let base = process.env['NX_BASE'];\n const head = process.env['NX_HEAD'];\n\n if (!base) {\n base = detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n\\u23ed\\ufe0f Skipping modified files validation (could not detect base branch)');\n console.log(' To run explicitly: nx affected --target=validate-modified-files --base=origin/main');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n\\ud83d\\udccf Validating Modified File Sizes (auto-detected base)\\n');\n } else {\n console.log('\\n\\ud83d\\udccf Validating Modified File Sizes\\n');\n }\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log(` Mode: ${mode}`);\n console.log(` Max lines for modified files: ${limit}`);\n console.log(` Disable allowed: ${disableAllowed}${!disableAllowed ? ' (no escape hatch)' : ''}`);\n console.log('');\n\n try {\n const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);\n\n if (changedFiles.length === 0) {\n console.log('\\u2705 No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`\\ud83d\\udcc2 Checking ${changedFiles.length} changed file(s)...`);\n\n const violations = findViolations(workspaceRoot, changedFiles, limit, disableAllowed);\n\n if (violations.length === 0) {\n console.log('\\u2705 All modified files are under ' + limit + ' lines');\n return { success: true };\n }\n\n writeTmpInstructions(workspaceRoot);\n reportViolations(violations, limit, disableAllowed);\n return { success: false };\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('\\u274c Modified files validation failed:', error.message);\n return { success: false };\n }\n}\n"]}