@webpieces/dev-config 0.2.95 → 0.2.98

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 (181) 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/src/executors/validate-eslint-sync/executor.js.map +1 -0
  7. package/{executors → src/executors}/validate-versions-locked/executor.js +2 -1
  8. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  9. package/src/index.d.ts +1 -1
  10. package/src/index.js +1 -1
  11. package/src/index.js.map +1 -1
  12. package/src/plugin.d.ts +86 -0
  13. package/{plugin.js → src/plugin.js} +31 -15
  14. package/src/plugin.js.map +1 -0
  15. package/src/toError.d.ts +5 -0
  16. package/src/toError.js +37 -0
  17. package/src/toError.js.map +1 -0
  18. package/templates/eslint.webpieces.config.mjs +1 -1
  19. package/architecture/executors/diff-utils.d.ts +0 -24
  20. package/architecture/executors/diff-utils.js +0 -119
  21. package/architecture/executors/diff-utils.js.map +0 -1
  22. package/architecture/executors/diff-utils.ts +0 -127
  23. package/architecture/executors/generate/executor.d.ts +0 -16
  24. package/architecture/executors/generate/executor.js +0 -44
  25. package/architecture/executors/generate/executor.js.map +0 -1
  26. package/architecture/executors/generate/executor.ts +0 -59
  27. package/architecture/executors/generate/schema.json +0 -14
  28. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
  29. package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
  30. package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
  31. package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
  32. package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
  33. package/architecture/executors/validate-code/executor.d.ts +0 -78
  34. package/architecture/executors/validate-code/executor.js +0 -243
  35. package/architecture/executors/validate-code/executor.js.map +0 -1
  36. package/architecture/executors/validate-code/executor.ts +0 -406
  37. package/architecture/executors/validate-code/schema.json +0 -227
  38. package/architecture/executors/validate-dtos/executor.d.ts +0 -42
  39. package/architecture/executors/validate-dtos/executor.js +0 -561
  40. package/architecture/executors/validate-dtos/executor.js.map +0 -1
  41. package/architecture/executors/validate-dtos/executor.ts +0 -689
  42. package/architecture/executors/validate-dtos/schema.json +0 -33
  43. package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
  44. package/architecture/executors/validate-modified-files/executor.js +0 -501
  45. package/architecture/executors/validate-modified-files/executor.js.map +0 -1
  46. package/architecture/executors/validate-modified-files/executor.ts +0 -571
  47. package/architecture/executors/validate-modified-files/schema.json +0 -25
  48. package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
  49. package/architecture/executors/validate-modified-methods/executor.js +0 -694
  50. package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
  51. package/architecture/executors/validate-modified-methods/executor.ts +0 -797
  52. package/architecture/executors/validate-modified-methods/schema.json +0 -25
  53. package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
  54. package/architecture/executors/validate-new-methods/executor.js +0 -513
  55. package/architecture/executors/validate-new-methods/executor.js.map +0 -1
  56. package/architecture/executors/validate-new-methods/executor.ts +0 -584
  57. package/architecture/executors/validate-new-methods/schema.json +0 -25
  58. package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
  59. package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
  60. package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
  61. package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
  62. package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
  63. package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
  64. package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
  65. package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
  66. package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
  67. package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
  68. package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
  69. package/architecture/executors/validate-no-destructure/executor.js +0 -491
  70. package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
  71. package/architecture/executors/validate-no-destructure/executor.ts +0 -578
  72. package/architecture/executors/validate-no-destructure/schema.json +0 -24
  73. package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
  74. package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
  75. package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
  76. package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
  77. package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
  78. package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
  79. package/architecture/executors/validate-no-inline-types/executor.js +0 -669
  80. package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
  81. package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
  82. package/architecture/executors/validate-no-inline-types/schema.json +0 -24
  83. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
  84. package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
  85. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
  86. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
  87. package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
  88. package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
  89. package/architecture/executors/validate-packagejson/executor.js +0 -57
  90. package/architecture/executors/validate-packagejson/executor.js.map +0 -1
  91. package/architecture/executors/validate-packagejson/executor.ts +0 -74
  92. package/architecture/executors/validate-packagejson/schema.json +0 -8
  93. package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
  94. package/architecture/executors/validate-prisma-converters/executor.js +0 -634
  95. package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
  96. package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
  97. package/architecture/executors/validate-prisma-converters/schema.json +0 -38
  98. package/architecture/executors/validate-return-types/executor.d.ts +0 -29
  99. package/architecture/executors/validate-return-types/executor.js +0 -439
  100. package/architecture/executors/validate-return-types/executor.js.map +0 -1
  101. package/architecture/executors/validate-return-types/executor.ts +0 -524
  102. package/architecture/executors/validate-return-types/schema.json +0 -24
  103. package/architecture/executors/visualize/executor.d.ts +0 -17
  104. package/architecture/executors/visualize/executor.js +0 -49
  105. package/architecture/executors/visualize/executor.js.map +0 -1
  106. package/architecture/executors/visualize/executor.ts +0 -63
  107. package/architecture/executors/visualize/schema.json +0 -14
  108. package/architecture/index.d.ts +0 -19
  109. package/architecture/index.js +0 -23
  110. package/architecture/index.js.map +0 -1
  111. package/architecture/index.ts +0 -20
  112. package/architecture/lib/graph-comparator.d.ts +0 -39
  113. package/architecture/lib/graph-comparator.js +0 -100
  114. package/architecture/lib/graph-comparator.js.map +0 -1
  115. package/architecture/lib/graph-comparator.ts +0 -141
  116. package/architecture/lib/graph-generator.d.ts +0 -19
  117. package/architecture/lib/graph-generator.js +0 -84
  118. package/architecture/lib/graph-generator.js.map +0 -1
  119. package/architecture/lib/graph-generator.ts +0 -97
  120. package/architecture/lib/graph-loader.d.ts +0 -31
  121. package/architecture/lib/graph-loader.js +0 -98
  122. package/architecture/lib/graph-loader.js.map +0 -1
  123. package/architecture/lib/graph-loader.ts +0 -116
  124. package/architecture/lib/graph-sorter.d.ts +0 -37
  125. package/architecture/lib/graph-sorter.js +0 -110
  126. package/architecture/lib/graph-sorter.js.map +0 -1
  127. package/architecture/lib/graph-sorter.ts +0 -137
  128. package/architecture/lib/graph-visualizer.d.ts +0 -29
  129. package/architecture/lib/graph-visualizer.js +0 -217
  130. package/architecture/lib/graph-visualizer.js.map +0 -1
  131. package/architecture/lib/graph-visualizer.ts +0 -231
  132. package/architecture/lib/package-validator.d.ts +0 -38
  133. package/architecture/lib/package-validator.js +0 -126
  134. package/architecture/lib/package-validator.js.map +0 -1
  135. package/architecture/lib/package-validator.ts +0 -170
  136. package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -374
  137. package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
  138. package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
  139. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
  140. package/eslint-plugin/index.d.ts +0 -23
  141. package/eslint-plugin/index.js +0 -30
  142. package/eslint-plugin/index.js.map +0 -1
  143. package/eslint-plugin/index.ts +0 -29
  144. package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
  145. package/eslint-plugin/rules/catch-error-pattern.js +0 -143
  146. package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
  147. package/eslint-plugin/rules/catch-error-pattern.ts +0 -246
  148. package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
  149. package/eslint-plugin/rules/enforce-architecture.js +0 -476
  150. package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
  151. package/eslint-plugin/rules/enforce-architecture.ts +0 -543
  152. package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
  153. package/eslint-plugin/rules/max-file-lines.js +0 -257
  154. package/eslint-plugin/rules/max-file-lines.js.map +0 -1
  155. package/eslint-plugin/rules/max-file-lines.ts +0 -272
  156. package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
  157. package/eslint-plugin/rules/max-method-lines.js +0 -240
  158. package/eslint-plugin/rules/max-method-lines.js.map +0 -1
  159. package/eslint-plugin/rules/max-method-lines.ts +0 -287
  160. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
  161. package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
  162. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
  163. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
  164. package/executors/help/executor.js.map +0 -1
  165. package/executors/help/executor.ts +0 -61
  166. package/executors/validate-eslint-sync/executor.js.map +0 -1
  167. package/executors/validate-eslint-sync/executor.ts +0 -87
  168. package/executors/validate-versions-locked/executor.js.map +0 -1
  169. package/executors/validate-versions-locked/executor.ts +0 -368
  170. package/plugin/README.md +0 -243
  171. package/plugin/index.d.ts +0 -4
  172. package/plugin/index.js +0 -8
  173. package/plugin/index.js.map +0 -1
  174. package/plugin/index.ts +0 -4
  175. /package/{executors → src/executors}/help/executor.js +0 -0
  176. /package/{executors → src/executors}/help/schema.json +0 -0
  177. /package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +0 -0
  178. /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
  179. /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
  180. /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
  181. /package/{executors → src/executors}/validate-versions-locked/schema.json +0 -0
@@ -1,25 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "title": "Validate Modified Methods Executor",
4
- "description": "Validates that modified methods don't exceed a maximum line count. Encourages gradual cleanup of legacy long methods.",
5
- "type": "object",
6
- "properties": {
7
- "limit": {
8
- "type": "number",
9
- "description": "Maximum lines allowed for modified methods",
10
- "default": 80
11
- },
12
- "mode": {
13
- "type": "string",
14
- "enum": ["OFF", "NEW_METHODS", "NEW_AND_MODIFIED_METHODS", "MODIFIED_FILES"],
15
- "description": "OFF: skip validation. NEW_AND_MODIFIED_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files.",
16
- "default": "NEW_AND_MODIFIED_METHODS"
17
- },
18
- "disableAllowed": {
19
- "type": "boolean",
20
- "description": "Whether disable comments work. When false, no escape hatch (like old STRICT mode).",
21
- "default": true
22
- }
23
- },
24
- "required": []
25
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Validate New Methods Executor
3
- *
4
- * Validates that newly added methods don't exceed a maximum line count.
5
- * Runs in affected mode when:
6
- * 1. NX_BASE environment variable is set (via nx affected), OR
7
- * 2. Auto-detects base by finding merge-base with origin/main
8
- *
9
- * This validator encourages writing methods that read like a "table of contents"
10
- * where each method call describes a larger piece of work.
11
- *
12
- * Usage:
13
- * nx affected --target=validate-new-methods --base=origin/main
14
- * OR: runs automatically via build's architecture:validate-complete dependency
15
- *
16
- * Escape hatch: Add webpieces-disable max-lines-new-methods comment with justification
17
- */
18
- import type { ExecutorContext } from '@nx/devkit';
19
- export type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
20
- export interface ValidateNewMethodsOptions {
21
- limit?: number;
22
- mode?: MethodMaxLimitMode;
23
- disableAllowed?: boolean;
24
- }
25
- export interface ExecutorResult {
26
- success: boolean;
27
- }
28
- export default function runExecutor(options: ValidateNewMethodsOptions, context: ExecutorContext): Promise<ExecutorResult>;
@@ -1,513 +0,0 @@
1
- "use strict";
2
- /**
3
- * Validate New Methods Executor
4
- *
5
- * Validates that newly added methods don't exceed a maximum line count.
6
- * Runs in affected mode when:
7
- * 1. NX_BASE environment variable is set (via nx affected), OR
8
- * 2. Auto-detects base by finding merge-base with origin/main
9
- *
10
- * This validator encourages writing methods that read like a "table of contents"
11
- * where each method call describes a larger piece of work.
12
- *
13
- * Usage:
14
- * nx affected --target=validate-new-methods --base=origin/main
15
- * OR: runs automatically via build's architecture:validate-complete dependency
16
- *
17
- * Escape hatch: Add webpieces-disable max-lines-new-methods comment with justification
18
- */
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.default = runExecutor;
21
- const tslib_1 = require("tslib");
22
- const child_process_1 = require("child_process");
23
- const fs = tslib_1.__importStar(require("fs"));
24
- const path = tslib_1.__importStar(require("path"));
25
- const ts = tslib_1.__importStar(require("typescript"));
26
- const TMP_DIR = 'tmp/webpieces';
27
- const TMP_MD_FILE = 'webpieces.methodsize.md';
28
- const METHODSIZE_DOC_CONTENT = `# Instructions: New Method Too Long
29
-
30
- ## Requirement
31
-
32
- **~99% of the time**, you can stay under the \`limit\` from nx.json
33
- by extracting logical units into well-named methods.
34
- Nearly all software can be written with methods under this size.
35
-
36
- ## The "Table of Contents" Principle
37
-
38
- Good code reads like a book's table of contents:
39
- - Chapter titles (method names) tell you WHAT happens
40
- - Reading chapter titles gives you the full story
41
- - You can dive into chapters (implementations) for details
42
-
43
- ## Why Limit New Methods?
44
-
45
- Methods under the limit are:
46
- - Easy to review in a single screen
47
- - Simple to understand without scrolling
48
- - Quick for AI to analyze and suggest improvements
49
- - More testable in isolation
50
- - Self-documenting through well-named extracted methods
51
-
52
- Extracting logical units into well-named methods makes code more readable for both
53
- AI and humans.
54
-
55
- ## How to Refactor
56
-
57
- Instead of:
58
- \`\`\`typescript
59
- async processOrder(order: Order): Promise<Result> {
60
- // 50 lines of validation, transformation, saving, notifications...
61
- }
62
- \`\`\`
63
-
64
- Write:
65
- \`\`\`typescript
66
- async processOrder(order: Order): Promise<Result> {
67
- const validated = this.validateOrder(order);
68
- const transformed = this.applyBusinessRules(validated);
69
- const saved = await this.saveToDatabase(transformed);
70
- await this.notifyStakeholders(saved);
71
- return this.buildResult(saved);
72
- }
73
- \`\`\`
74
-
75
- Now the main method is a "table of contents" - each line tells part of the story!
76
-
77
- ## Patterns for Extraction
78
-
79
- ### Pattern 1: Extract Loop Bodies
80
- \`\`\`typescript
81
- // BEFORE
82
- for (const item of items) {
83
- // 20 lines of processing
84
- }
85
-
86
- // AFTER
87
- for (const item of items) {
88
- this.processItem(item);
89
- }
90
- \`\`\`
91
-
92
- ### Pattern 2: Extract Conditional Blocks
93
- \`\`\`typescript
94
- // BEFORE
95
- if (isAdmin(user)) {
96
- // 15 lines of admin logic
97
- }
98
-
99
- // AFTER
100
- if (isAdmin(user)) {
101
- this.handleAdminUser(user);
102
- }
103
- \`\`\`
104
-
105
- ### Pattern 3: Extract Data Transformations
106
- \`\`\`typescript
107
- // BEFORE
108
- const result = {
109
- // 10+ lines of object construction
110
- };
111
-
112
- // AFTER
113
- const result = this.buildResultObject(data);
114
- \`\`\`
115
-
116
- ## If Refactoring Is Not Feasible
117
-
118
- Sometimes methods genuinely need to be longer (complex algorithms, state machines, etc.).
119
-
120
- **Escape hatch**: Add a webpieces-disable comment with justification:
121
-
122
- \`\`\`typescript
123
- // webpieces-disable max-lines-new-methods -- Complex state machine, splitting reduces clarity
124
- async complexStateMachine(): Promise<void> {
125
- // ... longer method with justification
126
- }
127
- \`\`\`
128
-
129
- ## AI Agent Action Steps
130
-
131
- 1. **READ** the method to understand its logical sections
132
- 2. **IDENTIFY** logical units that can be extracted
133
- 3. **EXTRACT** into well-named private methods
134
- 4. **VERIFY** the main method now reads like a table of contents
135
- 5. **IF NOT FEASIBLE**: Add webpieces-disable max-lines-new-methods comment with clear justification
136
-
137
- ## Remember
138
-
139
- - Every method you write today will be read many times tomorrow
140
- - The best code explains itself through structure
141
- - When in doubt, extract and name it
142
- `;
143
- /**
144
- * Write the instructions documentation to tmp directory
145
- */
146
- function writeTmpInstructions(workspaceRoot) {
147
- const tmpDir = path.join(workspaceRoot, TMP_DIR);
148
- const mdPath = path.join(tmpDir, TMP_MD_FILE);
149
- fs.mkdirSync(tmpDir, { recursive: true });
150
- fs.writeFileSync(mdPath, METHODSIZE_DOC_CONTENT);
151
- return mdPath;
152
- }
153
- /**
154
- * Get changed TypeScript files between base and head (or working tree if head not specified).
155
- * Uses `git diff base [head]` to match what `nx affected` does.
156
- * When head is NOT specified, also includes untracked files (matching nx affected behavior).
157
- */
158
- function getChangedTypeScriptFiles(workspaceRoot, base, head) {
159
- try {
160
- // If head is specified, diff base to head; otherwise diff base to working tree
161
- const diffTarget = head ? `${base} ${head}` : base;
162
- const output = (0, child_process_1.execSync)(`git diff --name-only ${diffTarget} -- '*.ts' '*.tsx'`, {
163
- cwd: workspaceRoot,
164
- encoding: 'utf-8',
165
- });
166
- const changedFiles = output
167
- .trim()
168
- .split('\n')
169
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
170
- // When comparing to working tree (no head specified), also include untracked files
171
- // This matches what nx affected does: "All modified files not yet committed or tracked will also be added"
172
- if (!head) {
173
- try {
174
- const untrackedOutput = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard '*.ts' '*.tsx'`, {
175
- cwd: workspaceRoot,
176
- encoding: 'utf-8',
177
- });
178
- const untrackedFiles = untrackedOutput
179
- .trim()
180
- .split('\n')
181
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
182
- // Merge and dedupe
183
- const allFiles = new Set([...changedFiles, ...untrackedFiles]);
184
- return Array.from(allFiles);
185
- }
186
- catch {
187
- // If ls-files fails, just return the changed files
188
- return changedFiles;
189
- }
190
- }
191
- return changedFiles;
192
- }
193
- catch {
194
- return [];
195
- }
196
- }
197
- /**
198
- * Get the diff content for a specific file between base and head (or working tree if head not specified).
199
- * Uses `git diff base [head]` to match what `nx affected` does.
200
- * For untracked files, returns the entire file content as additions.
201
- */
202
- function getFileDiff(workspaceRoot, file, base, head) {
203
- try {
204
- // If head is specified, diff base to head; otherwise diff base to working tree
205
- const diffTarget = head ? `${base} ${head}` : base;
206
- const diff = (0, child_process_1.execSync)(`git diff ${diffTarget} -- "${file}"`, {
207
- cwd: workspaceRoot,
208
- encoding: 'utf-8',
209
- });
210
- // If diff is empty and we're comparing to working tree, check if it's an untracked file
211
- if (!diff && !head) {
212
- const fullPath = path.join(workspaceRoot, file);
213
- if (fs.existsSync(fullPath)) {
214
- // Check if file is untracked
215
- const isUntracked = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard "${file}"`, {
216
- cwd: workspaceRoot,
217
- encoding: 'utf-8',
218
- }).trim();
219
- if (isUntracked) {
220
- // For untracked files, treat entire content as additions
221
- const content = fs.readFileSync(fullPath, 'utf-8');
222
- const lines = content.split('\n');
223
- // Create a pseudo-diff where all lines are additions
224
- return lines.map((line) => `+${line}`).join('\n');
225
- }
226
- }
227
- }
228
- return diff;
229
- }
230
- catch {
231
- return '';
232
- }
233
- }
234
- /**
235
- * Parse diff to find newly added method signatures
236
- */
237
- function findNewMethodSignaturesInDiff(diffContent) {
238
- const newMethods = new Set();
239
- const lines = diffContent.split('\n');
240
- // Patterns to match method definitions
241
- const patterns = [
242
- // [export] [async] function methodName( - most explicit, check first
243
- /^\+\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/,
244
- // [export] const/let methodName = [async] (
245
- /^\+\s*(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s*)?\(/,
246
- // [export] const/let methodName = [async] function
247
- /^\+\s*(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s+)?function/,
248
- // class method: [public/private/protected] [static] [async] methodName( - but NOT constructor, if, for, while, etc.
249
- /^\+\s*(?:(?:public|private|protected)\s+)?(?:static\s+)?(?:async\s+)?(\w+)\s*\(/,
250
- ];
251
- for (const line of lines) {
252
- if (line.startsWith('+') && !line.startsWith('+++')) {
253
- for (const pattern of patterns) {
254
- const match = line.match(pattern);
255
- if (match) {
256
- // Extract method name - now always in capture group 1
257
- const methodName = match[1];
258
- if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {
259
- newMethods.add(methodName);
260
- }
261
- break;
262
- }
263
- }
264
- }
265
- }
266
- return newMethods;
267
- }
268
- /**
269
- * Check if a line contains a webpieces-disable comment that exempts from new method validation.
270
- * Both max-lines-new-methods AND max-lines-modified are accepted here.
271
- */
272
- function hasDisableComment(lines, lineNumber) {
273
- // Check the line before the method (lineNumber is 1-indexed, array is 0-indexed)
274
- // We need to check a few lines before in case there's JSDoc or decorators
275
- const startCheck = Math.max(0, lineNumber - 5);
276
- for (let i = lineNumber - 2; i >= startCheck; i--) {
277
- const line = lines[i]?.trim() ?? '';
278
- // Stop if we hit another function/class/etc
279
- if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {
280
- break;
281
- }
282
- if (line.includes('webpieces-disable')) {
283
- // Either escape hatch exempts from the lowLimit new method check
284
- if (line.includes('max-lines-new-methods') || line.includes('max-lines-modified')) {
285
- return true;
286
- }
287
- }
288
- }
289
- return false;
290
- }
291
- /**
292
- * Parse a TypeScript file and find methods with their line counts
293
- */
294
- // webpieces-disable max-lines-new-methods -- AST traversal requires inline visitor function
295
- function findMethodsInFile(filePath, workspaceRoot) {
296
- const fullPath = path.join(workspaceRoot, filePath);
297
- if (!fs.existsSync(fullPath))
298
- return [];
299
- const content = fs.readFileSync(fullPath, 'utf-8');
300
- const fileLines = content.split('\n');
301
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
302
- const methods = [];
303
- function visit(node) {
304
- let methodName;
305
- let startLine;
306
- let endLine;
307
- if (ts.isMethodDeclaration(node) && node.name) {
308
- methodName = node.name.getText(sourceFile);
309
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
310
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
311
- startLine = start.line + 1;
312
- endLine = end.line + 1;
313
- }
314
- else if (ts.isFunctionDeclaration(node) && node.name) {
315
- methodName = node.name.getText(sourceFile);
316
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
317
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
318
- startLine = start.line + 1;
319
- endLine = end.line + 1;
320
- }
321
- else if (ts.isArrowFunction(node)) {
322
- // Check if it's assigned to a variable
323
- if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
324
- methodName = node.parent.name.getText(sourceFile);
325
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
326
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
327
- startLine = start.line + 1;
328
- endLine = end.line + 1;
329
- }
330
- }
331
- if (methodName && startLine !== undefined && endLine !== undefined) {
332
- methods.push({
333
- name: methodName,
334
- line: startLine,
335
- lines: endLine - startLine + 1,
336
- hasDisableComment: hasDisableComment(fileLines, startLine),
337
- });
338
- }
339
- ts.forEachChild(node, visit);
340
- }
341
- visit(sourceFile);
342
- return methods;
343
- }
344
- /**
345
- * Find new methods that exceed the line limit
346
- */
347
- function findViolations(workspaceRoot, changedFiles, base, limit, disableAllowed, head) {
348
- const violations = [];
349
- for (const file of changedFiles) {
350
- // Get the diff to find which methods are NEW (not just modified)
351
- const diff = getFileDiff(workspaceRoot, file, base, head);
352
- const newMethodNames = findNewMethodSignaturesInDiff(diff);
353
- if (newMethodNames.size === 0)
354
- continue;
355
- // Parse the current file to get method line counts
356
- const methods = findMethodsInFile(file, workspaceRoot);
357
- for (const method of methods) {
358
- if (!newMethodNames.has(method.name))
359
- continue;
360
- if (method.lines > limit) {
361
- if (!disableAllowed) {
362
- // No escape possible
363
- violations.push({
364
- file,
365
- methodName: method.name,
366
- line: method.line,
367
- lines: method.lines,
368
- isNew: true,
369
- limit,
370
- });
371
- }
372
- else if (!method.hasDisableComment) {
373
- // Escape allowed but not present
374
- violations.push({
375
- file,
376
- methodName: method.name,
377
- line: method.line,
378
- lines: method.lines,
379
- isNew: true,
380
- limit,
381
- });
382
- }
383
- }
384
- }
385
- }
386
- return violations;
387
- }
388
- /**
389
- * Auto-detect the base branch by finding the merge-base with origin/main.
390
- * This allows the executor to run even when NX_BASE isn't set (e.g., via dependsOn).
391
- */
392
- function detectBase(workspaceRoot) {
393
- try {
394
- // First, try to get merge-base with origin/main
395
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD origin/main', {
396
- cwd: workspaceRoot,
397
- encoding: 'utf-8',
398
- stdio: ['pipe', 'pipe', 'pipe'],
399
- }).trim();
400
- if (mergeBase) {
401
- return mergeBase;
402
- }
403
- }
404
- catch {
405
- // origin/main might not exist, try main
406
- try {
407
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD main', {
408
- cwd: workspaceRoot,
409
- encoding: 'utf-8',
410
- stdio: ['pipe', 'pipe', 'pipe'],
411
- }).trim();
412
- if (mergeBase) {
413
- return mergeBase;
414
- }
415
- }
416
- catch {
417
- // Ignore - will return null
418
- }
419
- }
420
- return null;
421
- }
422
- /**
423
- * Report violations to the user with helpful instructions
424
- */
425
- function reportViolations(violations, limit, disableAllowed) {
426
- console.error('');
427
- console.error('\u274c New methods exceed ' + limit + ' line limit!');
428
- console.error('');
429
- console.error('\ud83d\udcda Methods should read like a "table of contents" - each method call');
430
- console.error(' describes a larger piece of work.');
431
- console.error('');
432
- console.error('\u26a0\ufe0f *** READ tmp/webpieces/webpieces.methodsize.md for detailed guidance on how to fix this easily *** \u26a0\ufe0f');
433
- console.error('');
434
- if (disableAllowed) {
435
- console.error('\u26a0\ufe0f VIOLATIONS (can use escape hatch):');
436
- }
437
- else {
438
- console.error('\ud83d\udeab VIOLATIONS (cannot be bypassed with disable comment):');
439
- }
440
- console.error('');
441
- for (const v of violations) {
442
- console.error(` \u274c ${v.file}:${v.line}`);
443
- console.error(` Method: ${v.methodName} (${v.lines} lines, limit: ${limit})`);
444
- }
445
- console.error('');
446
- if (disableAllowed) {
447
- console.error(' Use escape: // webpieces-disable max-lines-new-methods -- [your reason]');
448
- }
449
- else {
450
- console.error(' These methods MUST be refactored - no escape hatch available (disableAllowed=false).');
451
- }
452
- console.error('');
453
- }
454
- async function runExecutor(options, context) {
455
- const workspaceRoot = context.root;
456
- const limit = options.limit ?? 80;
457
- const mode = options.mode ?? 'NEW_AND_MODIFIED_METHODS';
458
- const disableAllowed = options.disableAllowed ?? true;
459
- // Skip validation entirely if mode is OFF
460
- if (mode === 'OFF') {
461
- console.log('\n\u23ed\ufe0f Skipping new method validation (mode: OFF)');
462
- console.log('');
463
- return { success: true };
464
- }
465
- // Check if running in affected mode via NX_BASE, or auto-detect
466
- // If NX_HEAD is set (via nx affected --head=X), use it; otherwise compare to working tree
467
- let base = process.env['NX_BASE'];
468
- const head = process.env['NX_HEAD'];
469
- if (!base) {
470
- // Try to auto-detect base from git merge-base
471
- base = detectBase(workspaceRoot) ?? undefined;
472
- if (!base) {
473
- console.log('\n\u23ed\ufe0f Skipping new method validation (could not detect base branch)');
474
- console.log(' To run explicitly: nx affected --target=validate-new-methods --base=origin/main');
475
- console.log('');
476
- return { success: true };
477
- }
478
- console.log('\n\ud83d\udccf Validating New Method Sizes (auto-detected base)\n');
479
- }
480
- else {
481
- console.log('\n\ud83d\udccf Validating New Method Sizes\n');
482
- }
483
- console.log(` Base: ${base}`);
484
- console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
485
- console.log(` Mode: ${mode}`);
486
- console.log(` Limit for new methods: ${limit} lines (${disableAllowed ? 'can escape' : 'NO escape possible'})`);
487
- console.log('');
488
- try {
489
- // Get changed TypeScript files (base to head, or working tree if head not set)
490
- const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);
491
- if (changedFiles.length === 0) {
492
- console.log('\u2705 No TypeScript files changed');
493
- return { success: true };
494
- }
495
- console.log(`\ud83d\udcc2 Checking ${changedFiles.length} changed file(s)...`);
496
- // Find violations
497
- const violations = findViolations(workspaceRoot, changedFiles, base, limit, disableAllowed, head);
498
- if (violations.length === 0) {
499
- console.log('\u2705 All new methods are within ' + limit + ' lines');
500
- return { success: true };
501
- }
502
- // Write instructions file and report violations
503
- writeTmpInstructions(workspaceRoot);
504
- reportViolations(violations, limit, disableAllowed);
505
- return { success: false };
506
- }
507
- catch (err) {
508
- const error = err instanceof Error ? err : new Error(String(err));
509
- console.error('\u274c New method validation failed:', error.message);
510
- return { success: false };
511
- }
512
- }
513
- //# sourceMappingURL=executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-new-methods/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AA+eH,8BAwEC;;AApjBD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AA8BjC,MAAM,OAAO,GAAG,eAAe,CAAC;AAChC,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAE9C,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkH9B,CAAC;AAEF;;GAEG;AACH,SAAS,oBAA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\n * Validates that newly added methods don't exceed a maximum line count.\n * Runs in affected mode when:\n * 1. NX_BASE environment variable is set (via nx affected), OR\n * 2. Auto-detects base by finding merge-base with origin/main\n *\n * This validator encourages writing methods that read like a \"table of contents\"\n * where each method call describes a larger piece of work.\n *\n * Usage:\n * nx affected --target=validate-new-methods --base=origin/main\n * OR: runs automatically via build's architecture:validate-complete dependency\n *\n * Escape hatch: Add webpieces-disable max-lines-new-methods comment with justification\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\n\nexport type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';\n\nexport interface ValidateNewMethodsOptions {\n limit?: number;\n mode?: MethodMaxLimitMode;\n disableAllowed?: boolean;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface MethodViolation {\n file: string;\n methodName: string;\n line: number;\n lines: number;\n isNew: boolean;\n limit: number;\n}\n\ninterface MethodInfo {\n name: string;\n line: number;\n lines: number;\n hasDisableComment: boolean;\n}\n\nconst TMP_DIR = 'tmp/webpieces';\nconst TMP_MD_FILE = 'webpieces.methodsize.md';\n\nconst METHODSIZE_DOC_CONTENT = `# Instructions: New Method Too Long\n\n## Requirement\n\n**~99% of the time**, you can stay under the \\`limit\\` from nx.json\nby extracting logical units into well-named methods.\nNearly all software can be written with methods under this size.\n\n## The \"Table of Contents\" Principle\n\nGood code reads like a book's table of contents:\n- Chapter titles (method names) tell you WHAT happens\n- Reading chapter titles gives you the full story\n- You can dive into chapters (implementations) for details\n\n## Why Limit New Methods?\n\nMethods under the limit are:\n- Easy to review in a single screen\n- Simple to understand without scrolling\n- Quick for AI to analyze and suggest improvements\n- More testable in isolation\n- Self-documenting through well-named extracted methods\n\nExtracting logical units into well-named methods makes code more readable for both\nAI and humans.\n\n## How to Refactor\n\nInstead of:\n\\`\\`\\`typescript\nasync processOrder(order: Order): Promise<Result> {\n // 50 lines of validation, transformation, saving, notifications...\n}\n\\`\\`\\`\n\nWrite:\n\\`\\`\\`typescript\nasync processOrder(order: Order): Promise<Result> {\n const validated = this.validateOrder(order);\n const transformed = this.applyBusinessRules(validated);\n const saved = await this.saveToDatabase(transformed);\n await this.notifyStakeholders(saved);\n return this.buildResult(saved);\n}\n\\`\\`\\`\n\nNow the main method is a \"table of contents\" - each line tells part of the story!\n\n## Patterns for Extraction\n\n### Pattern 1: Extract Loop Bodies\n\\`\\`\\`typescript\n// BEFORE\nfor (const item of items) {\n // 20 lines of processing\n}\n\n// AFTER\nfor (const item of items) {\n this.processItem(item);\n}\n\\`\\`\\`\n\n### Pattern 2: Extract Conditional Blocks\n\\`\\`\\`typescript\n// BEFORE\nif (isAdmin(user)) {\n // 15 lines of admin logic\n}\n\n// AFTER\nif (isAdmin(user)) {\n this.handleAdminUser(user);\n}\n\\`\\`\\`\n\n### Pattern 3: Extract Data Transformations\n\\`\\`\\`typescript\n// BEFORE\nconst result = {\n // 10+ lines of object construction\n};\n\n// AFTER\nconst result = this.buildResultObject(data);\n\\`\\`\\`\n\n## If Refactoring Is Not Feasible\n\nSometimes methods genuinely need to be longer (complex algorithms, state machines, etc.).\n\n**Escape hatch**: Add a webpieces-disable comment with justification:\n\n\\`\\`\\`typescript\n// webpieces-disable max-lines-new-methods -- Complex state machine, splitting reduces clarity\nasync complexStateMachine(): Promise<void> {\n // ... longer method with justification\n}\n\\`\\`\\`\n\n## AI Agent Action Steps\n\n1. **READ** the method to understand its logical sections\n2. **IDENTIFY** logical units that can be extracted\n3. **EXTRACT** into well-named private methods\n4. **VERIFY** the main method now reads like a table of contents\n5. **IF NOT FEASIBLE**: Add webpieces-disable max-lines-new-methods comment with clear justification\n\n## Remember\n\n- Every method you write today will be read many times tomorrow\n- The best code explains itself through structure\n- When in doubt, extract and name it\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, METHODSIZE_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 * Get the diff content for a specific file between base and head (or working tree if head not specified).\n * Uses `git diff base [head]` to match what `nx affected` does.\n * For untracked files, returns the entire file content as additions.\n */\nfunction getFileDiff(workspaceRoot: string, file: 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 diff = execSync(`git diff ${diffTarget} -- \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n\n // If diff is empty and we're comparing to working tree, check if it's an untracked file\n if (!diff && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\n // Check if file is untracked\n const isUntracked = execSync(`git ls-files --others --exclude-standard \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }).trim();\n\n if (isUntracked) {\n // For untracked files, treat entire content as additions\n const content = fs.readFileSync(fullPath, 'utf-8');\n const lines = content.split('\\n');\n // Create a pseudo-diff where all lines are additions\n return lines.map((line) => `+${line}`).join('\\n');\n }\n }\n }\n\n return diff;\n } catch {\n return '';\n }\n}\n\n/**\n * Parse diff to find newly added method signatures\n */\nfunction findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n const newMethods = new Set<string>();\n const lines = diffContent.split('\\n');\n\n // Patterns to match method definitions\n const patterns = [\n // [export] [async] function methodName( - most explicit, check first\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n // [export] const/let methodName = [async] (\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n // [export] const/let methodName = [async] function\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\n // class method: [public/private/protected] [static] [async] methodName( - but NOT constructor, if, for, while, etc.\n /^\\+\\s*(?:(?:public|private|protected)\\s+)?(?:static\\s+)?(?:async\\s+)?(\\w+)\\s*\\(/,\n ];\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n for (const pattern of patterns) {\n const match = line.match(pattern);\n if (match) {\n // Extract method name - now always in capture group 1\n const methodName = match[1];\n if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {\n newMethods.add(methodName);\n }\n break;\n }\n }\n }\n }\n\n return newMethods;\n}\n\n/**\n * Check if a line contains a webpieces-disable comment that exempts from new method validation.\n * Both max-lines-new-methods AND max-lines-modified are accepted here.\n */\nfunction hasDisableComment(lines: string[], lineNumber: number): boolean {\n // Check the line before the method (lineNumber is 1-indexed, array is 0-indexed)\n // We need to check a few lines before in case there's JSDoc or decorators\n const startCheck = Math.max(0, lineNumber - 5);\n for (let i = lineNumber - 2; i >= startCheck; i--) {\n const line = lines[i]?.trim() ?? '';\n // Stop if we hit another function/class/etc\n if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {\n break;\n }\n if (line.includes('webpieces-disable')) {\n // Either escape hatch exempts from the lowLimit new method check\n if (line.includes('max-lines-new-methods') || line.includes('max-lines-modified')) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Parse a TypeScript file and find methods with their line counts\n */\n// webpieces-disable max-lines-new-methods -- AST traversal requires inline visitor function\nfunction findMethodsInFile(filePath: string, workspaceRoot: string): MethodInfo[] {\n const fullPath = path.join(workspaceRoot, filePath);\n if (!fs.existsSync(fullPath)) return [];\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const fileLines = content.split('\\n');\n const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);\n\n const methods: MethodInfo[] = [];\n\n function visit(node: ts.Node): void {\n let methodName: string | undefined;\n let startLine: number | undefined;\n let endLine: number | undefined;\n\n if (ts.isMethodDeclaration(node) && node.name) {\n methodName = node.name.getText(sourceFile);\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());\n startLine = start.line + 1;\n endLine = end.line + 1;\n } else if (ts.isFunctionDeclaration(node) && node.name) {\n methodName = node.name.getText(sourceFile);\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());\n startLine = start.line + 1;\n endLine = end.line + 1;\n } else if (ts.isArrowFunction(node)) {\n // Check if it's assigned to a variable\n if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {\n methodName = node.parent.name.getText(sourceFile);\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());\n startLine = start.line + 1;\n endLine = end.line + 1;\n }\n }\n\n if (methodName && startLine !== undefined && endLine !== undefined) {\n methods.push({\n name: methodName,\n line: startLine,\n lines: endLine - startLine + 1,\n hasDisableComment: hasDisableComment(fileLines, startLine),\n });\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return methods;\n}\n\n/**\n * Find new methods that exceed the line limit\n */\nfunction findViolations(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n limit: number,\n disableAllowed: boolean,\n head?: string\n): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n // Get the diff to find which methods are NEW (not just modified)\n const diff = getFileDiff(workspaceRoot, file, base, head);\n const newMethodNames = findNewMethodSignaturesInDiff(diff);\n\n if (newMethodNames.size === 0) continue;\n\n // Parse the current file to get method line counts\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (!newMethodNames.has(method.name)) continue;\n\n if (method.lines > limit) {\n if (!disableAllowed) {\n // No escape possible\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n lines: method.lines,\n isNew: true,\n limit,\n });\n } else if (!method.hasDisableComment) {\n // Escape allowed but not present\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n lines: method.lines,\n isNew: true,\n limit,\n });\n }\n }\n }\n }\n\n return violations;\n}\n\n/**\n * Auto-detect the base branch by finding the merge-base with origin/main.\n * This allows the executor to run even when NX_BASE isn't set (e.g., via dependsOn).\n */\nfunction detectBase(workspaceRoot: string): string | null {\n try {\n // First, try to get merge-base with origin/main\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 // origin/main might not exist, try main\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 - will return null\n }\n }\n return null;\n}\n\n/**\n * Report violations to the user with helpful instructions\n */\nfunction reportViolations(violations: MethodViolation[], limit: number, disableAllowed: boolean): void {\n console.error('');\n console.error('\\u274c New methods exceed ' + limit + ' line limit!');\n console.error('');\n console.error('\\ud83d\\udcda Methods should read like a \"table of contents\" - each method call');\n console.error(' describes a larger piece of work.');\n console.error('');\n console.error('\\u26a0\\ufe0f *** READ tmp/webpieces/webpieces.methodsize.md for detailed guidance on how to fix this easily *** \\u26a0\\ufe0f');\n console.error('');\n\n if (disableAllowed) {\n console.error('\\u26a0\\ufe0f VIOLATIONS (can use escape hatch):');\n } else {\n console.error('\\ud83d\\udeab VIOLATIONS (cannot be bypassed with disable comment):');\n }\n console.error('');\n for (const v of violations) {\n console.error(` \\u274c ${v.file}:${v.line}`);\n console.error(` Method: ${v.methodName} (${v.lines} lines, limit: ${limit})`);\n }\n console.error('');\n if (disableAllowed) {\n console.error(' Use escape: // webpieces-disable max-lines-new-methods -- [your reason]');\n } else {\n console.error(' These methods MUST be refactored - no escape hatch available (disableAllowed=false).');\n }\n console.error('');\n}\n\nexport default async function runExecutor(\n options: ValidateNewMethodsOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const limit = options.limit ?? 80;\n const mode: MethodMaxLimitMode = options.mode ?? 'NEW_AND_MODIFIED_METHODS';\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 new method validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n // Check if running in affected mode via NX_BASE, or auto-detect\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 // Try to auto-detect base from git merge-base\n base = detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n\\u23ed\\ufe0f Skipping new method validation (could not detect base branch)');\n console.log(' To run explicitly: nx affected --target=validate-new-methods --base=origin/main');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n\\ud83d\\udccf Validating New Method Sizes (auto-detected base)\\n');\n } else {\n console.log('\\n\\ud83d\\udccf Validating New Method 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(` Limit for new methods: ${limit} lines (${disableAllowed ? 'can escape' : 'NO escape possible'})`);\n console.log('');\n\n try {\n // Get changed TypeScript files (base to head, or working tree if head not set)\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 // Find violations\n const violations = findViolations(workspaceRoot, changedFiles, base, limit, disableAllowed, head);\n\n if (violations.length === 0) {\n console.log('\\u2705 All new methods are within ' + limit + ' lines');\n return { success: true };\n }\n\n // Write instructions file and report violations\n writeTmpInstructions(workspaceRoot);\n reportViolations(violations, limit, disableAllowed);\n\n return { success: false };\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('\\u274c New method validation failed:', error.message);\n return { success: false };\n }\n}\n"]}