@webpieces/dev-config 0.2.71 → 0.2.73
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.
- package/architecture/executors/validate-code/schema.json +2 -2
- package/architecture/executors/validate-return-types/executor.d.ts +4 -3
- package/architecture/executors/validate-return-types/executor.js +96 -18
- package/architecture/executors/validate-return-types/executor.js.map +1 -1
- package/architecture/executors/validate-return-types/executor.ts +113 -25
- package/architecture/executors/validate-return-types/schema.json +3 -3
- package/package.json +1 -1
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"requireReturnTypeMode": {
|
|
33
33
|
"type": "string",
|
|
34
|
-
"enum": ["OFF", "
|
|
35
|
-
"description": "OFF: skip return type validation.
|
|
34
|
+
"enum": ["OFF", "NEW_METHODS", "MODIFIED_AND_NEW_METHODS", "MODIFIED_FILES", "ALL"],
|
|
35
|
+
"description": "OFF: skip return type validation. NEW_METHODS: only new methods in diff. MODIFIED_AND_NEW_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files. ALL: all methods everywhere.",
|
|
36
36
|
"default": "OFF"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Modes:
|
|
12
12
|
* - OFF: Skip validation entirely
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
13
|
+
* - NEW_METHODS: Only validate new methods (detected via git diff)
|
|
14
|
+
* - MODIFIED_AND_NEW_METHODS: Validate new methods + methods with changes in their line range
|
|
15
|
+
* - MODIFIED_FILES: Validate all methods in modified files
|
|
15
16
|
* - ALL: Validate all methods in all TypeScript files
|
|
16
17
|
*
|
|
17
18
|
* Escape hatch: Add webpieces-disable require-return-type comment with justification
|
|
18
19
|
*/
|
|
19
20
|
import type { ExecutorContext } from '@nx/devkit';
|
|
20
|
-
export type ReturnTypeMode = 'OFF' | '
|
|
21
|
+
export type ReturnTypeMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';
|
|
21
22
|
export interface ValidateReturnTypesOptions {
|
|
22
23
|
mode?: ReturnTypeMode;
|
|
23
24
|
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Modes:
|
|
13
13
|
* - OFF: Skip validation entirely
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
14
|
+
* - NEW_METHODS: Only validate new methods (detected via git diff)
|
|
15
|
+
* - MODIFIED_AND_NEW_METHODS: Validate new methods + methods with changes in their line range
|
|
16
|
+
* - MODIFIED_FILES: Validate all methods in modified files
|
|
16
17
|
* - ALL: Validate all methods in all TypeScript files
|
|
17
18
|
*
|
|
18
19
|
* Escape hatch: Add webpieces-disable require-return-type comment with justification
|
|
@@ -63,18 +64,18 @@ function getChangedTypeScriptFiles(workspaceRoot, base, head) {
|
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
|
-
* Get all TypeScript files in the workspace (excluding
|
|
67
|
+
* Get all TypeScript files in the workspace using git ls-files (excluding tests).
|
|
67
68
|
*/
|
|
68
69
|
function getAllTypeScriptFiles(workspaceRoot) {
|
|
69
70
|
try {
|
|
70
|
-
const output = (0, child_process_1.execSync)(`
|
|
71
|
+
const output = (0, child_process_1.execSync)(`git ls-files '*.ts' '*.tsx'`, {
|
|
71
72
|
cwd: workspaceRoot,
|
|
72
73
|
encoding: 'utf-8',
|
|
73
74
|
});
|
|
74
75
|
return output
|
|
75
76
|
.trim()
|
|
76
77
|
.split('\n')
|
|
77
|
-
.filter((f) => f);
|
|
78
|
+
.filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
|
|
78
79
|
}
|
|
79
80
|
catch {
|
|
80
81
|
return [];
|
|
@@ -176,31 +177,39 @@ function findMethodsInFile(filePath, workspaceRoot) {
|
|
|
176
177
|
function visit(node) {
|
|
177
178
|
let methodName;
|
|
178
179
|
let startLine;
|
|
180
|
+
let endLine;
|
|
179
181
|
let hasReturnType = false;
|
|
180
182
|
if (ts.isMethodDeclaration(node) && node.name) {
|
|
181
183
|
methodName = node.name.getText(sourceFile);
|
|
182
184
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
185
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
183
186
|
startLine = start.line + 1;
|
|
187
|
+
endLine = end.line + 1;
|
|
184
188
|
hasReturnType = hasExplicitReturnType(node);
|
|
185
189
|
}
|
|
186
190
|
else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
187
191
|
methodName = node.name.getText(sourceFile);
|
|
188
192
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
193
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
189
194
|
startLine = start.line + 1;
|
|
195
|
+
endLine = end.line + 1;
|
|
190
196
|
hasReturnType = hasExplicitReturnType(node);
|
|
191
197
|
}
|
|
192
198
|
else if (ts.isArrowFunction(node)) {
|
|
193
199
|
if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
|
|
194
200
|
methodName = node.parent.name.getText(sourceFile);
|
|
195
201
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
202
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
196
203
|
startLine = start.line + 1;
|
|
204
|
+
endLine = end.line + 1;
|
|
197
205
|
hasReturnType = hasExplicitReturnType(node);
|
|
198
206
|
}
|
|
199
207
|
}
|
|
200
|
-
if (methodName && startLine !== undefined) {
|
|
208
|
+
if (methodName && startLine !== undefined && endLine !== undefined) {
|
|
201
209
|
methods.push({
|
|
202
210
|
name: methodName,
|
|
203
211
|
line: startLine,
|
|
212
|
+
endLine,
|
|
204
213
|
hasReturnType,
|
|
205
214
|
hasDisableComment: hasDisableComment(fileLines, startLine),
|
|
206
215
|
});
|
|
@@ -211,10 +220,47 @@ function findMethodsInFile(filePath, workspaceRoot) {
|
|
|
211
220
|
return methods;
|
|
212
221
|
}
|
|
213
222
|
/**
|
|
214
|
-
*
|
|
223
|
+
* Parse diff to extract changed line numbers (both additions and modifications).
|
|
224
|
+
*/
|
|
225
|
+
function getChangedLineNumbers(diffContent) {
|
|
226
|
+
const changedLines = new Set();
|
|
227
|
+
const lines = diffContent.split('\n');
|
|
228
|
+
let currentLine = 0;
|
|
229
|
+
for (const line of lines) {
|
|
230
|
+
const hunkMatch = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
231
|
+
if (hunkMatch) {
|
|
232
|
+
currentLine = parseInt(hunkMatch[1], 10);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
236
|
+
changedLines.add(currentLine);
|
|
237
|
+
currentLine++;
|
|
238
|
+
}
|
|
239
|
+
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
240
|
+
// Deletions don't increment line number
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
currentLine++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return changedLines;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Check if a method has any changed lines within its range.
|
|
250
|
+
*/
|
|
251
|
+
function methodHasChanges(method, changedLines) {
|
|
252
|
+
for (let line = method.line; line <= method.endLine; line++) {
|
|
253
|
+
if (changedLines.has(line)) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Find NEW methods without explicit return types (NEW_METHODS mode).
|
|
215
261
|
*/
|
|
216
262
|
// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and method matching
|
|
217
|
-
function
|
|
263
|
+
function findViolationsForNewMethods(workspaceRoot, changedFiles, base, head) {
|
|
218
264
|
const violations = [];
|
|
219
265
|
for (const file of changedFiles) {
|
|
220
266
|
const diff = getFileDiff(workspaceRoot, file, base, head);
|
|
@@ -239,17 +285,25 @@ function findViolationsForModifiedNew(workspaceRoot, changedFiles, base, head) {
|
|
|
239
285
|
return violations;
|
|
240
286
|
}
|
|
241
287
|
/**
|
|
242
|
-
* Find
|
|
288
|
+
* Find NEW methods AND methods with changes (MODIFIED_AND_NEW_METHODS mode).
|
|
243
289
|
*/
|
|
244
|
-
|
|
290
|
+
// webpieces-disable max-lines-new-methods -- Combines new method detection with change detection
|
|
291
|
+
function findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head) {
|
|
245
292
|
const violations = [];
|
|
246
293
|
for (const file of changedFiles) {
|
|
294
|
+
const diff = getFileDiff(workspaceRoot, file, base, head);
|
|
295
|
+
const newMethodNames = findNewMethodSignaturesInDiff(diff);
|
|
296
|
+
const changedLines = getChangedLineNumbers(diff);
|
|
247
297
|
const methods = findMethodsInFile(file, workspaceRoot);
|
|
248
298
|
for (const method of methods) {
|
|
249
299
|
if (method.hasReturnType)
|
|
250
300
|
continue;
|
|
251
301
|
if (method.hasDisableComment)
|
|
252
302
|
continue;
|
|
303
|
+
const isNewMethod = newMethodNames.has(method.name);
|
|
304
|
+
const isModifiedMethod = methodHasChanges(method, changedLines);
|
|
305
|
+
if (!isNewMethod && !isModifiedMethod)
|
|
306
|
+
continue;
|
|
253
307
|
violations.push({
|
|
254
308
|
file,
|
|
255
309
|
methodName: method.name,
|
|
@@ -260,11 +314,32 @@ function findViolationsForModified(workspaceRoot, changedFiles) {
|
|
|
260
314
|
return violations;
|
|
261
315
|
}
|
|
262
316
|
/**
|
|
263
|
-
* Find all methods without explicit return types in
|
|
317
|
+
* Find all methods without explicit return types in modified files (MODIFIED_FILES mode).
|
|
318
|
+
*/
|
|
319
|
+
function findViolationsForModifiedFiles(workspaceRoot, changedFiles) {
|
|
320
|
+
const violations = [];
|
|
321
|
+
for (const file of changedFiles) {
|
|
322
|
+
const methods = findMethodsInFile(file, workspaceRoot);
|
|
323
|
+
for (const method of methods) {
|
|
324
|
+
if (method.hasReturnType)
|
|
325
|
+
continue;
|
|
326
|
+
if (method.hasDisableComment)
|
|
327
|
+
continue;
|
|
328
|
+
violations.push({
|
|
329
|
+
file,
|
|
330
|
+
methodName: method.name,
|
|
331
|
+
line: method.line,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return violations;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Find all methods without explicit return types in all files (ALL mode).
|
|
264
339
|
*/
|
|
265
340
|
function findViolationsForAll(workspaceRoot) {
|
|
266
341
|
const allFiles = getAllTypeScriptFiles(workspaceRoot);
|
|
267
|
-
return
|
|
342
|
+
return findViolationsForModifiedFiles(workspaceRoot, allFiles);
|
|
268
343
|
}
|
|
269
344
|
/**
|
|
270
345
|
* Auto-detect the base branch by finding the merge-base with origin/main.
|
|
@@ -325,7 +400,7 @@ function reportViolations(violations, mode) {
|
|
|
325
400
|
}
|
|
326
401
|
async function runExecutor(options, context) {
|
|
327
402
|
const workspaceRoot = context.root;
|
|
328
|
-
const mode = options.mode ?? '
|
|
403
|
+
const mode = options.mode ?? 'NEW_METHODS';
|
|
329
404
|
if (mode === 'OFF') {
|
|
330
405
|
console.log('\n⏭️ Skipping return type validation (mode: OFF)');
|
|
331
406
|
console.log('');
|
|
@@ -335,7 +410,7 @@ async function runExecutor(options, context) {
|
|
|
335
410
|
console.log(` Mode: ${mode}`);
|
|
336
411
|
let violations = [];
|
|
337
412
|
if (mode === 'ALL') {
|
|
338
|
-
console.log(' Scope: All TypeScript files');
|
|
413
|
+
console.log(' Scope: All tracked TypeScript files');
|
|
339
414
|
console.log('');
|
|
340
415
|
violations = findViolationsForAll(workspaceRoot);
|
|
341
416
|
}
|
|
@@ -359,11 +434,14 @@ async function runExecutor(options, context) {
|
|
|
359
434
|
return { success: true };
|
|
360
435
|
}
|
|
361
436
|
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
362
|
-
if (mode === '
|
|
363
|
-
violations =
|
|
437
|
+
if (mode === 'NEW_METHODS') {
|
|
438
|
+
violations = findViolationsForNewMethods(workspaceRoot, changedFiles, base, head);
|
|
439
|
+
}
|
|
440
|
+
else if (mode === 'MODIFIED_AND_NEW_METHODS') {
|
|
441
|
+
violations = findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head);
|
|
364
442
|
}
|
|
365
|
-
else if (mode === '
|
|
366
|
-
violations =
|
|
443
|
+
else if (mode === 'MODIFIED_FILES') {
|
|
444
|
+
violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles);
|
|
367
445
|
}
|
|
368
446
|
}
|
|
369
447
|
if (violations.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-return-types/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AA4WH,8BAgEC;;AAzaD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AAkBjC;;GAEG;AACH,oHAAoH;AACpH,SAAS,yBAAyB,CAAC,aAAqB,EAAE,IAAY,EAAE,IAAa;IACjF,IAAI,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnD,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,UAAU,oBAAoB,EAAE;YAC5E,GAAG,EAAE,aAAa;YAClB,QAAQ,EAAE,OAAO;SACpB,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,MAAM;aACtB,IAAI,EAAE;aACN,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,C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YAAY,IAAI,IAAI,6CAA6C,EAAE,CAAC,CAAC;QACjF,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEhB,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,+BAA+B,CAAC,CAAC;YAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,eAAe,YAAY,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAErE,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;YAC1B,UAAU,GAAG,4BAA4B,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACvF,CAAC;aAAM,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,UAAU,GAAG,yBAAyB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEnC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Validate Return Types Executor\n *\n * Validates that methods have explicit return type annotations for better code readability.\n * Instead of relying on TypeScript's type inference, explicit return types make code clearer:\n *\n * BAD: method() { return new MyClass(); }\n * GOOD: method(): MyClass { return new MyClass(); }\n * GOOD: async method(): Promise<MyType> { ... }\n *\n * Modes:\n * - OFF: Skip validation entirely\n * - MODIFIED_NEW: Only validate new methods (detected via git diff)\n * - MODIFIED: Validate all methods in modified files\n * - ALL: Validate all methods in all TypeScript files\n *\n * Escape hatch: Add webpieces-disable require-return-type 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 ReturnTypeMode = 'OFF' | 'MODIFIED_NEW' | 'MODIFIED' | 'ALL';\n\nexport interface ValidateReturnTypesOptions {\n mode?: ReturnTypeMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface MethodViolation {\n file: string;\n methodName: string;\n line: number;\n}\n\n/**\n * Get changed TypeScript files between base and head (or working tree if head not specified).\n */\n// webpieces-disable max-lines-new-methods -- Git command handling with untracked files requires multiple code paths\nfunction getChangedTypeScriptFiles(workspaceRoot: string, base: string, head?: string): string[] {\n try {\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 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 const allFiles = new Set([...changedFiles, ...untrackedFiles]);\n return Array.from(allFiles);\n } catch {\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch {\n return [];\n }\n}\n\n/**\n * Get all TypeScript files in the workspace (excluding node_modules, dist, tests).\n */\nfunction getAllTypeScriptFiles(workspaceRoot: string): string[] {\n try {\n const output = execSync(\n `find packages apps -type f \\\\( -name \"*.ts\" -o -name \"*.tsx\" \\\\) | grep -v node_modules | grep -v dist | grep -v \".spec.ts\" | grep -v \".test.ts\"`,\n {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }\n );\n return output\n .trim()\n .split('\\n')\n .filter((f) => f);\n } catch {\n return [];\n }\n}\n\n/**\n * Get the diff content for a specific file.\n */\nfunction getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n try {\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 && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\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 const content = fs.readFileSync(fullPath, 'utf-8');\n const lines = content.split('\\n');\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 const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\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 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 for return type.\n */\nfunction hasDisableComment(lines: string[], lineNumber: number): boolean {\n const startCheck = Math.max(0, lineNumber - 5);\n for (let i = lineNumber - 2; i >= startCheck; i--) {\n const line = lines[i]?.trim() ?? '';\n if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {\n break;\n }\n if (line.includes('webpieces-disable') && line.includes('require-return-type')) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Check if a method has an explicit return type annotation.\n */\nfunction hasExplicitReturnType(node: ts.MethodDeclaration | ts.FunctionDeclaration | ts.ArrowFunction): boolean {\n return node.type !== undefined;\n}\n\ninterface MethodInfo {\n name: string;\n line: number;\n hasReturnType: boolean;\n hasDisableComment: boolean;\n}\n\n/**\n * Parse a TypeScript file and find methods with their return type status.\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 // webpieces-disable max-lines-new-methods -- AST visitor pattern requires handling multiple node types\n function visit(node: ts.Node): void {\n let methodName: string | undefined;\n let startLine: number | undefined;\n let hasReturnType = false;\n\n if (ts.isMethodDeclaration(node) && node.name) {\n methodName = node.name.getText(sourceFile);\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n startLine = start.line + 1;\n hasReturnType = hasExplicitReturnType(node);\n } else if (ts.isFunctionDeclaration(node) && node.name) {\n methodName = node.name.getText(sourceFile);\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n startLine = start.line + 1;\n hasReturnType = hasExplicitReturnType(node);\n } else if (ts.isArrowFunction(node)) {\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 startLine = start.line + 1;\n hasReturnType = hasExplicitReturnType(node);\n }\n }\n\n if (methodName && startLine !== undefined) {\n methods.push({\n name: methodName,\n line: startLine,\n hasReturnType,\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 methods without explicit return types based on mode.\n */\n// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and method matching\nfunction findViolationsForModifiedNew(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head?: string\n): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n const diff = getFileDiff(workspaceRoot, file, base, head);\n const newMethodNames = findNewMethodSignaturesInDiff(diff);\n\n if (newMethodNames.size === 0) continue;\n\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (!newMethodNames.has(method.name)) continue;\n if (method.hasReturnType) continue;\n if (method.hasDisableComment) continue;\n\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all methods without explicit return types in modified files.\n */\nfunction findViolationsForModified(workspaceRoot: string, changedFiles: string[]): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (method.hasReturnType) continue;\n if (method.hasDisableComment) continue;\n\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all methods without explicit return types in all files.\n */\nfunction findViolationsForAll(workspaceRoot: string): MethodViolation[] {\n const allFiles = getAllTypeScriptFiles(workspaceRoot);\n return findViolationsForModified(workspaceRoot, allFiles);\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 * Report violations to console.\n */\nfunction reportViolations(violations: MethodViolation[], mode: ReturnTypeMode): void {\n console.error('');\n console.error('❌ Methods missing explicit return types!');\n console.error('');\n console.error('📚 Explicit return types improve code readability:');\n console.error('');\n console.error(' BAD: method() { return new MyClass(); }');\n console.error(' GOOD: method(): MyClass { return new MyClass(); }');\n console.error(' GOOD: async method(): Promise<MyType> { ... }');\n console.error('');\n\n for (const v of violations) {\n console.error(` ❌ ${v.file}:${v.line}`);\n console.error(` Method: ${v.methodName} - missing return type annotation`);\n }\n console.error('');\n\n console.error(' To fix: Add explicit return type after the parameter list');\n console.error('');\n console.error(' Escape hatch (use sparingly):');\n console.error(' // webpieces-disable require-return-type -- [your reason]');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n}\n\nexport default async function runExecutor(\n options: ValidateReturnTypesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const mode: ReturnTypeMode = options.mode ?? 'MODIFIED_NEW';\n\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping return type validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n📏 Validating Return Types\\n');\n console.log(` Mode: ${mode}`);\n\n let violations: MethodViolation[] = [];\n\n if (mode === 'ALL') {\n console.log(' Scope: All TypeScript files');\n console.log('');\n violations = findViolationsForAll(workspaceRoot);\n } else {\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⏭️ Skipping return type validation (could not detect base branch)');\n console.log('');\n return { success: true };\n }\n }\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);\n\n if (changedFiles.length === 0) {\n console.log('✅ No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n\n if (mode === 'MODIFIED_NEW') {\n violations = findViolationsForModifiedNew(workspaceRoot, changedFiles, base, head);\n } else if (mode === 'MODIFIED') {\n violations = findViolationsForModified(workspaceRoot, changedFiles);\n }\n }\n\n if (violations.length === 0) {\n console.log('✅ All methods have explicit return types');\n return { success: true };\n }\n\n reportViolations(violations, mode);\n\n return { success: false };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-return-types/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAicH,8BAkEC;;AAhgBD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AAkBjC;;GAEG;AACH,oHAAoH;AACpH,SAAS,yBAAyB,CAAC,aAAqB,EAAE,IAAY,EAAE,IAAa;IACjF,IAAI,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACnD,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,UAAU,oBAAoB,EAAE;YAC5E,GAAG,EAAE,aAAa;YAClB,QAAQ,EAAE,OAAO;SACpB,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,MAAM;aACtB,IAAI,EAAE;aACN,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU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AK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAEnC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Validate Return Types Executor\n *\n * Validates that methods have explicit return type annotations for better code readability.\n * Instead of relying on TypeScript's type inference, explicit return types make code clearer:\n *\n * BAD: method() { return new MyClass(); }\n * GOOD: method(): MyClass { return new MyClass(); }\n * GOOD: async method(): Promise<MyType> { ... }\n *\n * Modes:\n * - OFF: Skip validation entirely\n * - NEW_METHODS: Only validate new methods (detected via git diff)\n * - MODIFIED_AND_NEW_METHODS: Validate new methods + methods with changes in their line range\n * - MODIFIED_FILES: Validate all methods in modified files\n * - ALL: Validate all methods in all TypeScript files\n *\n * Escape hatch: Add webpieces-disable require-return-type 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 ReturnTypeMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';\n\nexport interface ValidateReturnTypesOptions {\n mode?: ReturnTypeMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface MethodViolation {\n file: string;\n methodName: string;\n line: number;\n}\n\n/**\n * Get changed TypeScript files between base and head (or working tree if head not specified).\n */\n// webpieces-disable max-lines-new-methods -- Git command handling with untracked files requires multiple code paths\nfunction getChangedTypeScriptFiles(workspaceRoot: string, base: string, head?: string): string[] {\n try {\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 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 const allFiles = new Set([...changedFiles, ...untrackedFiles]);\n return Array.from(allFiles);\n } catch {\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch {\n return [];\n }\n}\n\n/**\n * Get all TypeScript files in the workspace using git ls-files (excluding tests).\n */\nfunction getAllTypeScriptFiles(workspaceRoot: string): string[] {\n try {\n const output = execSync(`git ls-files '*.ts' '*.tsx'`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n return output\n .trim()\n .split('\\n')\n .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));\n } catch {\n return [];\n }\n}\n\n/**\n * Get the diff content for a specific file.\n */\nfunction getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n try {\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 && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\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 const content = fs.readFileSync(fullPath, 'utf-8');\n const lines = content.split('\\n');\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 const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\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 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 for return type.\n */\nfunction hasDisableComment(lines: string[], lineNumber: number): boolean {\n const startCheck = Math.max(0, lineNumber - 5);\n for (let i = lineNumber - 2; i >= startCheck; i--) {\n const line = lines[i]?.trim() ?? '';\n if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {\n break;\n }\n if (line.includes('webpieces-disable') && line.includes('require-return-type')) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Check if a method has an explicit return type annotation.\n */\nfunction hasExplicitReturnType(node: ts.MethodDeclaration | ts.FunctionDeclaration | ts.ArrowFunction): boolean {\n return node.type !== undefined;\n}\n\ninterface MethodInfo {\n name: string;\n line: number;\n endLine: number;\n hasReturnType: boolean;\n hasDisableComment: boolean;\n}\n\n/**\n * Parse a TypeScript file and find methods with their return type status.\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 // webpieces-disable max-lines-new-methods -- AST visitor pattern requires handling multiple node types\n function visit(node: ts.Node): void {\n let methodName: string | undefined;\n let startLine: number | undefined;\n let endLine: number | undefined;\n let hasReturnType = false;\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 hasReturnType = hasExplicitReturnType(node);\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 hasReturnType = hasExplicitReturnType(node);\n } else if (ts.isArrowFunction(node)) {\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 hasReturnType = hasExplicitReturnType(node);\n }\n }\n\n if (methodName && startLine !== undefined && endLine !== undefined) {\n methods.push({\n name: methodName,\n line: startLine,\n endLine,\n hasReturnType,\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 * Parse diff to extract changed line numbers (both additions and modifications).\n */\nfunction getChangedLineNumbers(diffContent: string): Set<number> {\n const changedLines = new Set<number>();\n const lines = diffContent.split('\\n');\n let currentLine = 0;\n\n for (const line of lines) {\n const hunkMatch = line.match(/^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/);\n if (hunkMatch) {\n currentLine = parseInt(hunkMatch[1], 10);\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n changedLines.add(currentLine);\n currentLine++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n // Deletions don't increment line number\n } else {\n currentLine++;\n }\n }\n\n return changedLines;\n}\n\n/**\n * Check if a method has any changed lines within its range.\n */\nfunction methodHasChanges(method: MethodInfo, changedLines: Set<number>): boolean {\n for (let line = method.line; line <= method.endLine; line++) {\n if (changedLines.has(line)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Find NEW methods without explicit return types (NEW_METHODS mode).\n */\n// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and method matching\nfunction findViolationsForNewMethods(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head?: string\n): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n const diff = getFileDiff(workspaceRoot, file, base, head);\n const newMethodNames = findNewMethodSignaturesInDiff(diff);\n\n if (newMethodNames.size === 0) continue;\n\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (!newMethodNames.has(method.name)) continue;\n if (method.hasReturnType) continue;\n if (method.hasDisableComment) continue;\n\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find NEW methods AND methods with changes (MODIFIED_AND_NEW_METHODS mode).\n */\n// webpieces-disable max-lines-new-methods -- Combines new method detection with change detection\nfunction findViolationsForModifiedAndNewMethods(\n workspaceRoot: string,\n changedFiles: string[],\n base: string,\n head?: string\n): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n const diff = getFileDiff(workspaceRoot, file, base, head);\n const newMethodNames = findNewMethodSignaturesInDiff(diff);\n const changedLines = getChangedLineNumbers(diff);\n\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (method.hasReturnType) continue;\n if (method.hasDisableComment) continue;\n\n const isNewMethod = newMethodNames.has(method.name);\n const isModifiedMethod = methodHasChanges(method, changedLines);\n\n if (!isNewMethod && !isModifiedMethod) continue;\n\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all methods without explicit return types in modified files (MODIFIED_FILES mode).\n */\nfunction findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[]): MethodViolation[] {\n const violations: MethodViolation[] = [];\n\n for (const file of changedFiles) {\n const methods = findMethodsInFile(file, workspaceRoot);\n\n for (const method of methods) {\n if (method.hasReturnType) continue;\n if (method.hasDisableComment) continue;\n\n violations.push({\n file,\n methodName: method.name,\n line: method.line,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all methods without explicit return types in all files (ALL mode).\n */\nfunction findViolationsForAll(workspaceRoot: string): MethodViolation[] {\n const allFiles = getAllTypeScriptFiles(workspaceRoot);\n return findViolationsForModifiedFiles(workspaceRoot, allFiles);\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 * Report violations to console.\n */\nfunction reportViolations(violations: MethodViolation[], mode: ReturnTypeMode): void {\n console.error('');\n console.error('❌ Methods missing explicit return types!');\n console.error('');\n console.error('📚 Explicit return types improve code readability:');\n console.error('');\n console.error(' BAD: method() { return new MyClass(); }');\n console.error(' GOOD: method(): MyClass { return new MyClass(); }');\n console.error(' GOOD: async method(): Promise<MyType> { ... }');\n console.error('');\n\n for (const v of violations) {\n console.error(` ❌ ${v.file}:${v.line}`);\n console.error(` Method: ${v.methodName} - missing return type annotation`);\n }\n console.error('');\n\n console.error(' To fix: Add explicit return type after the parameter list');\n console.error('');\n console.error(' Escape hatch (use sparingly):');\n console.error(' // webpieces-disable require-return-type -- [your reason]');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n}\n\nexport default async function runExecutor(\n options: ValidateReturnTypesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const mode: ReturnTypeMode = options.mode ?? 'NEW_METHODS';\n\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping return type validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n📏 Validating Return Types\\n');\n console.log(` Mode: ${mode}`);\n\n let violations: MethodViolation[] = [];\n\n if (mode === 'ALL') {\n console.log(' Scope: All tracked TypeScript files');\n console.log('');\n violations = findViolationsForAll(workspaceRoot);\n } else {\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⏭️ Skipping return type validation (could not detect base branch)');\n console.log('');\n return { success: true };\n }\n }\n\n console.log(` Base: ${base}`);\n console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);\n console.log('');\n\n const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);\n\n if (changedFiles.length === 0) {\n console.log('✅ No TypeScript files changed');\n return { success: true };\n }\n\n console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);\n\n if (mode === 'NEW_METHODS') {\n violations = findViolationsForNewMethods(workspaceRoot, changedFiles, base, head);\n } else if (mode === 'MODIFIED_AND_NEW_METHODS') {\n violations = findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head);\n } else if (mode === 'MODIFIED_FILES') {\n violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles);\n }\n }\n\n if (violations.length === 0) {\n console.log('✅ All methods have explicit return types');\n return { success: true };\n }\n\n reportViolations(violations, mode);\n\n return { success: false };\n}\n"]}
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Modes:
|
|
12
12
|
* - OFF: Skip validation entirely
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
13
|
+
* - NEW_METHODS: Only validate new methods (detected via git diff)
|
|
14
|
+
* - MODIFIED_AND_NEW_METHODS: Validate new methods + methods with changes in their line range
|
|
15
|
+
* - MODIFIED_FILES: Validate all methods in modified files
|
|
15
16
|
* - ALL: Validate all methods in all TypeScript files
|
|
16
17
|
*
|
|
17
18
|
* Escape hatch: Add webpieces-disable require-return-type comment with justification
|
|
@@ -23,7 +24,7 @@ import * as fs from 'fs';
|
|
|
23
24
|
import * as path from 'path';
|
|
24
25
|
import * as ts from 'typescript';
|
|
25
26
|
|
|
26
|
-
export type ReturnTypeMode = 'OFF' | '
|
|
27
|
+
export type ReturnTypeMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';
|
|
27
28
|
|
|
28
29
|
export interface ValidateReturnTypesOptions {
|
|
29
30
|
mode?: ReturnTypeMode;
|
|
@@ -79,21 +80,18 @@ function getChangedTypeScriptFiles(workspaceRoot: string, base: string, head?: s
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* Get all TypeScript files in the workspace (excluding
|
|
83
|
+
* Get all TypeScript files in the workspace using git ls-files (excluding tests).
|
|
83
84
|
*/
|
|
84
85
|
function getAllTypeScriptFiles(workspaceRoot: string): string[] {
|
|
85
86
|
try {
|
|
86
|
-
const output = execSync(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
encoding: 'utf-8',
|
|
91
|
-
}
|
|
92
|
-
);
|
|
87
|
+
const output = execSync(`git ls-files '*.ts' '*.tsx'`, {
|
|
88
|
+
cwd: workspaceRoot,
|
|
89
|
+
encoding: 'utf-8',
|
|
90
|
+
});
|
|
93
91
|
return output
|
|
94
92
|
.trim()
|
|
95
93
|
.split('\n')
|
|
96
|
-
.filter((f) => f);
|
|
94
|
+
.filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
|
|
97
95
|
} catch {
|
|
98
96
|
return [];
|
|
99
97
|
}
|
|
@@ -191,6 +189,7 @@ function hasExplicitReturnType(node: ts.MethodDeclaration | ts.FunctionDeclarati
|
|
|
191
189
|
interface MethodInfo {
|
|
192
190
|
name: string;
|
|
193
191
|
line: number;
|
|
192
|
+
endLine: number;
|
|
194
193
|
hasReturnType: boolean;
|
|
195
194
|
hasDisableComment: boolean;
|
|
196
195
|
}
|
|
@@ -213,31 +212,39 @@ function findMethodsInFile(filePath: string, workspaceRoot: string): MethodInfo[
|
|
|
213
212
|
function visit(node: ts.Node): void {
|
|
214
213
|
let methodName: string | undefined;
|
|
215
214
|
let startLine: number | undefined;
|
|
215
|
+
let endLine: number | undefined;
|
|
216
216
|
let hasReturnType = false;
|
|
217
217
|
|
|
218
218
|
if (ts.isMethodDeclaration(node) && node.name) {
|
|
219
219
|
methodName = node.name.getText(sourceFile);
|
|
220
220
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
221
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
221
222
|
startLine = start.line + 1;
|
|
223
|
+
endLine = end.line + 1;
|
|
222
224
|
hasReturnType = hasExplicitReturnType(node);
|
|
223
225
|
} else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
224
226
|
methodName = node.name.getText(sourceFile);
|
|
225
227
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
228
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
226
229
|
startLine = start.line + 1;
|
|
230
|
+
endLine = end.line + 1;
|
|
227
231
|
hasReturnType = hasExplicitReturnType(node);
|
|
228
232
|
} else if (ts.isArrowFunction(node)) {
|
|
229
233
|
if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
|
|
230
234
|
methodName = node.parent.name.getText(sourceFile);
|
|
231
235
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
236
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
232
237
|
startLine = start.line + 1;
|
|
238
|
+
endLine = end.line + 1;
|
|
233
239
|
hasReturnType = hasExplicitReturnType(node);
|
|
234
240
|
}
|
|
235
241
|
}
|
|
236
242
|
|
|
237
|
-
if (methodName && startLine !== undefined) {
|
|
243
|
+
if (methodName && startLine !== undefined && endLine !== undefined) {
|
|
238
244
|
methods.push({
|
|
239
245
|
name: methodName,
|
|
240
246
|
line: startLine,
|
|
247
|
+
endLine,
|
|
241
248
|
hasReturnType,
|
|
242
249
|
hasDisableComment: hasDisableComment(fileLines, startLine),
|
|
243
250
|
});
|
|
@@ -251,10 +258,50 @@ function findMethodsInFile(filePath: string, workspaceRoot: string): MethodInfo[
|
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
/**
|
|
254
|
-
*
|
|
261
|
+
* Parse diff to extract changed line numbers (both additions and modifications).
|
|
262
|
+
*/
|
|
263
|
+
function getChangedLineNumbers(diffContent: string): Set<number> {
|
|
264
|
+
const changedLines = new Set<number>();
|
|
265
|
+
const lines = diffContent.split('\n');
|
|
266
|
+
let currentLine = 0;
|
|
267
|
+
|
|
268
|
+
for (const line of lines) {
|
|
269
|
+
const hunkMatch = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
270
|
+
if (hunkMatch) {
|
|
271
|
+
currentLine = parseInt(hunkMatch[1], 10);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
276
|
+
changedLines.add(currentLine);
|
|
277
|
+
currentLine++;
|
|
278
|
+
} else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
279
|
+
// Deletions don't increment line number
|
|
280
|
+
} else {
|
|
281
|
+
currentLine++;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return changedLines;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Check if a method has any changed lines within its range.
|
|
290
|
+
*/
|
|
291
|
+
function methodHasChanges(method: MethodInfo, changedLines: Set<number>): boolean {
|
|
292
|
+
for (let line = method.line; line <= method.endLine; line++) {
|
|
293
|
+
if (changedLines.has(line)) {
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Find NEW methods without explicit return types (NEW_METHODS mode).
|
|
255
302
|
*/
|
|
256
303
|
// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and method matching
|
|
257
|
-
function
|
|
304
|
+
function findViolationsForNewMethods(
|
|
258
305
|
workspaceRoot: string,
|
|
259
306
|
changedFiles: string[],
|
|
260
307
|
base: string,
|
|
@@ -287,9 +334,48 @@ function findViolationsForModifiedNew(
|
|
|
287
334
|
}
|
|
288
335
|
|
|
289
336
|
/**
|
|
290
|
-
* Find
|
|
337
|
+
* Find NEW methods AND methods with changes (MODIFIED_AND_NEW_METHODS mode).
|
|
338
|
+
*/
|
|
339
|
+
// webpieces-disable max-lines-new-methods -- Combines new method detection with change detection
|
|
340
|
+
function findViolationsForModifiedAndNewMethods(
|
|
341
|
+
workspaceRoot: string,
|
|
342
|
+
changedFiles: string[],
|
|
343
|
+
base: string,
|
|
344
|
+
head?: string
|
|
345
|
+
): MethodViolation[] {
|
|
346
|
+
const violations: MethodViolation[] = [];
|
|
347
|
+
|
|
348
|
+
for (const file of changedFiles) {
|
|
349
|
+
const diff = getFileDiff(workspaceRoot, file, base, head);
|
|
350
|
+
const newMethodNames = findNewMethodSignaturesInDiff(diff);
|
|
351
|
+
const changedLines = getChangedLineNumbers(diff);
|
|
352
|
+
|
|
353
|
+
const methods = findMethodsInFile(file, workspaceRoot);
|
|
354
|
+
|
|
355
|
+
for (const method of methods) {
|
|
356
|
+
if (method.hasReturnType) continue;
|
|
357
|
+
if (method.hasDisableComment) continue;
|
|
358
|
+
|
|
359
|
+
const isNewMethod = newMethodNames.has(method.name);
|
|
360
|
+
const isModifiedMethod = methodHasChanges(method, changedLines);
|
|
361
|
+
|
|
362
|
+
if (!isNewMethod && !isModifiedMethod) continue;
|
|
363
|
+
|
|
364
|
+
violations.push({
|
|
365
|
+
file,
|
|
366
|
+
methodName: method.name,
|
|
367
|
+
line: method.line,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return violations;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Find all methods without explicit return types in modified files (MODIFIED_FILES mode).
|
|
291
377
|
*/
|
|
292
|
-
function
|
|
378
|
+
function findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[]): MethodViolation[] {
|
|
293
379
|
const violations: MethodViolation[] = [];
|
|
294
380
|
|
|
295
381
|
for (const file of changedFiles) {
|
|
@@ -311,11 +397,11 @@ function findViolationsForModified(workspaceRoot: string, changedFiles: string[]
|
|
|
311
397
|
}
|
|
312
398
|
|
|
313
399
|
/**
|
|
314
|
-
* Find all methods without explicit return types in all files.
|
|
400
|
+
* Find all methods without explicit return types in all files (ALL mode).
|
|
315
401
|
*/
|
|
316
402
|
function findViolationsForAll(workspaceRoot: string): MethodViolation[] {
|
|
317
403
|
const allFiles = getAllTypeScriptFiles(workspaceRoot);
|
|
318
|
-
return
|
|
404
|
+
return findViolationsForModifiedFiles(workspaceRoot, allFiles);
|
|
319
405
|
}
|
|
320
406
|
|
|
321
407
|
/**
|
|
@@ -384,7 +470,7 @@ export default async function runExecutor(
|
|
|
384
470
|
context: ExecutorContext
|
|
385
471
|
): Promise<ExecutorResult> {
|
|
386
472
|
const workspaceRoot = context.root;
|
|
387
|
-
const mode: ReturnTypeMode = options.mode ?? '
|
|
473
|
+
const mode: ReturnTypeMode = options.mode ?? 'NEW_METHODS';
|
|
388
474
|
|
|
389
475
|
if (mode === 'OFF') {
|
|
390
476
|
console.log('\n⏭️ Skipping return type validation (mode: OFF)');
|
|
@@ -398,7 +484,7 @@ export default async function runExecutor(
|
|
|
398
484
|
let violations: MethodViolation[] = [];
|
|
399
485
|
|
|
400
486
|
if (mode === 'ALL') {
|
|
401
|
-
console.log(' Scope: All TypeScript files');
|
|
487
|
+
console.log(' Scope: All tracked TypeScript files');
|
|
402
488
|
console.log('');
|
|
403
489
|
violations = findViolationsForAll(workspaceRoot);
|
|
404
490
|
} else {
|
|
@@ -428,10 +514,12 @@ export default async function runExecutor(
|
|
|
428
514
|
|
|
429
515
|
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
430
516
|
|
|
431
|
-
if (mode === '
|
|
432
|
-
violations =
|
|
433
|
-
} else if (mode === '
|
|
434
|
-
violations =
|
|
517
|
+
if (mode === 'NEW_METHODS') {
|
|
518
|
+
violations = findViolationsForNewMethods(workspaceRoot, changedFiles, base, head);
|
|
519
|
+
} else if (mode === 'MODIFIED_AND_NEW_METHODS') {
|
|
520
|
+
violations = findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head);
|
|
521
|
+
} else if (mode === 'MODIFIED_FILES') {
|
|
522
|
+
violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles);
|
|
435
523
|
}
|
|
436
524
|
}
|
|
437
525
|
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
"properties": {
|
|
7
7
|
"mode": {
|
|
8
8
|
"type": "string",
|
|
9
|
-
"enum": ["OFF", "
|
|
10
|
-
"description": "OFF: skip validation.
|
|
11
|
-
"default": "
|
|
9
|
+
"enum": ["OFF", "NEW_METHODS", "MODIFIED_AND_NEW_METHODS", "MODIFIED_FILES", "ALL"],
|
|
10
|
+
"description": "OFF: skip validation. NEW_METHODS: only new methods in diff. MODIFIED_AND_NEW_METHODS: new methods + methods with changes. MODIFIED_FILES: all methods in modified files. ALL: all methods everywhere.",
|
|
11
|
+
"default": "NEW_METHODS"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"required": []
|