@webpieces/dev-config 0.2.73 → 0.2.74
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/executor.d.ts +2 -0
- package/architecture/executors/validate-code/executor.js +6 -1
- package/architecture/executors/validate-code/executor.js.map +1 -1
- package/architecture/executors/validate-code/executor.ts +8 -1
- package/architecture/executors/validate-code/schema.json +6 -0
- package/architecture/executors/validate-no-inline-types/executor.d.ts +30 -0
- package/architecture/executors/validate-no-inline-types/executor.js +550 -0
- package/architecture/executors/validate-no-inline-types/executor.js.map +1 -0
- package/architecture/executors/validate-no-inline-types/executor.ts +649 -0
- package/architecture/executors/validate-no-inline-types/schema.json +15 -0
- package/executors.json +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validate No Inline Types Executor
|
|
4
|
+
*
|
|
5
|
+
* Validates that inline type literals are not used - prefer named types/interfaces/classes.
|
|
6
|
+
* Instead of anonymous object types, use named types for clarity and reusability:
|
|
7
|
+
*
|
|
8
|
+
* BAD: function foo(arg: { x: number }) { }
|
|
9
|
+
* GOOD: function foo(arg: MyConfig) { }
|
|
10
|
+
*
|
|
11
|
+
* BAD: type Nullable = { x: number } | null;
|
|
12
|
+
* GOOD: type MyData = { x: number }; type Nullable = MyData | null;
|
|
13
|
+
*
|
|
14
|
+
* Modes:
|
|
15
|
+
* - OFF: Skip validation entirely
|
|
16
|
+
* - NEW_METHODS: Only validate inline types in new methods (detected via git diff)
|
|
17
|
+
* - MODIFIED_AND_NEW_METHODS: Validate in new methods + methods with changes in their line range
|
|
18
|
+
* - MODIFIED_FILES: Validate all inline types in modified files
|
|
19
|
+
* - ALL: Validate all inline types in all TypeScript files
|
|
20
|
+
*
|
|
21
|
+
* Escape hatch: Add webpieces-disable no-inline-types comment with justification
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.default = runExecutor;
|
|
25
|
+
const tslib_1 = require("tslib");
|
|
26
|
+
const child_process_1 = require("child_process");
|
|
27
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
28
|
+
const path = tslib_1.__importStar(require("path"));
|
|
29
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
30
|
+
/**
|
|
31
|
+
* Get changed TypeScript files between base and head (or working tree if head not specified).
|
|
32
|
+
*/
|
|
33
|
+
// webpieces-disable max-lines-new-methods -- Git command handling with untracked files requires multiple code paths
|
|
34
|
+
function getChangedTypeScriptFiles(workspaceRoot, base, head) {
|
|
35
|
+
try {
|
|
36
|
+
const diffTarget = head ? `${base} ${head}` : base;
|
|
37
|
+
const output = (0, child_process_1.execSync)(`git diff --name-only ${diffTarget} -- '*.ts' '*.tsx'`, {
|
|
38
|
+
cwd: workspaceRoot,
|
|
39
|
+
encoding: 'utf-8',
|
|
40
|
+
});
|
|
41
|
+
const changedFiles = output
|
|
42
|
+
.trim()
|
|
43
|
+
.split('\n')
|
|
44
|
+
.filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
|
|
45
|
+
if (!head) {
|
|
46
|
+
try {
|
|
47
|
+
const untrackedOutput = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard '*.ts' '*.tsx'`, {
|
|
48
|
+
cwd: workspaceRoot,
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
});
|
|
51
|
+
const untrackedFiles = untrackedOutput
|
|
52
|
+
.trim()
|
|
53
|
+
.split('\n')
|
|
54
|
+
.filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
|
|
55
|
+
const allFiles = new Set([...changedFiles, ...untrackedFiles]);
|
|
56
|
+
return Array.from(allFiles);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return changedFiles;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return changedFiles;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all TypeScript files in the workspace using git ls-files (excluding tests).
|
|
70
|
+
*/
|
|
71
|
+
function getAllTypeScriptFiles(workspaceRoot) {
|
|
72
|
+
try {
|
|
73
|
+
const output = (0, child_process_1.execSync)(`git ls-files '*.ts' '*.tsx'`, {
|
|
74
|
+
cwd: workspaceRoot,
|
|
75
|
+
encoding: 'utf-8',
|
|
76
|
+
});
|
|
77
|
+
return output
|
|
78
|
+
.trim()
|
|
79
|
+
.split('\n')
|
|
80
|
+
.filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the diff content for a specific file.
|
|
88
|
+
*/
|
|
89
|
+
function getFileDiff(workspaceRoot, file, base, head) {
|
|
90
|
+
try {
|
|
91
|
+
const diffTarget = head ? `${base} ${head}` : base;
|
|
92
|
+
const diff = (0, child_process_1.execSync)(`git diff ${diffTarget} -- "${file}"`, {
|
|
93
|
+
cwd: workspaceRoot,
|
|
94
|
+
encoding: 'utf-8',
|
|
95
|
+
});
|
|
96
|
+
if (!diff && !head) {
|
|
97
|
+
const fullPath = path.join(workspaceRoot, file);
|
|
98
|
+
if (fs.existsSync(fullPath)) {
|
|
99
|
+
const isUntracked = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard "${file}"`, {
|
|
100
|
+
cwd: workspaceRoot,
|
|
101
|
+
encoding: 'utf-8',
|
|
102
|
+
}).trim();
|
|
103
|
+
if (isUntracked) {
|
|
104
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
105
|
+
const lines = content.split('\n');
|
|
106
|
+
return lines.map((line) => `+${line}`).join('\n');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return diff;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Parse diff to extract changed line numbers (both additions and modifications).
|
|
118
|
+
*/
|
|
119
|
+
function getChangedLineNumbers(diffContent) {
|
|
120
|
+
const changedLines = new Set();
|
|
121
|
+
const lines = diffContent.split('\n');
|
|
122
|
+
let currentLine = 0;
|
|
123
|
+
for (const line of lines) {
|
|
124
|
+
const hunkMatch = line.match(/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
125
|
+
if (hunkMatch) {
|
|
126
|
+
currentLine = parseInt(hunkMatch[1], 10);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
130
|
+
changedLines.add(currentLine);
|
|
131
|
+
currentLine++;
|
|
132
|
+
}
|
|
133
|
+
else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
134
|
+
// Deletions don't increment line number
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
currentLine++;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return changedLines;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if a line contains a webpieces-disable comment for no-inline-types.
|
|
144
|
+
*/
|
|
145
|
+
function hasDisableComment(lines, lineNumber) {
|
|
146
|
+
const startCheck = Math.max(0, lineNumber - 5);
|
|
147
|
+
for (let i = lineNumber - 2; i >= startCheck; i--) {
|
|
148
|
+
const line = lines[i]?.trim() ?? '';
|
|
149
|
+
if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
if (line.includes('webpieces-disable') && line.includes('no-inline-types')) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if a TypeLiteral node is in an allowed context.
|
|
160
|
+
* Only allowed if the DIRECT parent is a TypeAliasDeclaration.
|
|
161
|
+
*/
|
|
162
|
+
function isInAllowedContext(node) {
|
|
163
|
+
const parent = node.parent;
|
|
164
|
+
// Only allowed if it's the DIRECT body of a type alias
|
|
165
|
+
if (ts.isTypeAliasDeclaration(parent)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get a description of the context where the inline type appears.
|
|
172
|
+
*/
|
|
173
|
+
// webpieces-disable max-lines-new-methods -- Context detection requires checking many AST node types
|
|
174
|
+
function getViolationContext(node, sourceFile) {
|
|
175
|
+
let current = node;
|
|
176
|
+
while (current.parent) {
|
|
177
|
+
const parent = current.parent;
|
|
178
|
+
if (ts.isParameter(parent)) {
|
|
179
|
+
return 'inline parameter type';
|
|
180
|
+
}
|
|
181
|
+
if (ts.isFunctionDeclaration(parent) || ts.isMethodDeclaration(parent) || ts.isArrowFunction(parent)) {
|
|
182
|
+
if (parent.type === current) {
|
|
183
|
+
return 'inline return type';
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (ts.isVariableDeclaration(parent)) {
|
|
187
|
+
return 'inline variable type';
|
|
188
|
+
}
|
|
189
|
+
if (ts.isPropertyDeclaration(parent) || ts.isPropertySignature(parent)) {
|
|
190
|
+
if (parent.type === current) {
|
|
191
|
+
return 'inline property type';
|
|
192
|
+
}
|
|
193
|
+
// Check if it's nested inside another type literal
|
|
194
|
+
let ancestor = parent.parent;
|
|
195
|
+
while (ancestor) {
|
|
196
|
+
if (ts.isTypeLiteralNode(ancestor)) {
|
|
197
|
+
return 'nested inline type';
|
|
198
|
+
}
|
|
199
|
+
if (ts.isTypeAliasDeclaration(ancestor)) {
|
|
200
|
+
return 'nested inline type in type alias';
|
|
201
|
+
}
|
|
202
|
+
ancestor = ancestor.parent;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent)) {
|
|
206
|
+
return 'inline type in union/intersection';
|
|
207
|
+
}
|
|
208
|
+
if (ts.isTypeReferenceNode(parent.parent) && ts.isTypeNode(parent)) {
|
|
209
|
+
return 'inline type in generic argument';
|
|
210
|
+
}
|
|
211
|
+
current = parent;
|
|
212
|
+
}
|
|
213
|
+
return 'inline type literal';
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Find all methods/functions in a file with their line ranges.
|
|
217
|
+
*/
|
|
218
|
+
// webpieces-disable max-lines-new-methods -- AST traversal requires inline visitor function
|
|
219
|
+
function findMethodsInFile(filePath, workspaceRoot) {
|
|
220
|
+
const fullPath = path.join(workspaceRoot, filePath);
|
|
221
|
+
if (!fs.existsSync(fullPath))
|
|
222
|
+
return [];
|
|
223
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
224
|
+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
225
|
+
const methods = [];
|
|
226
|
+
// webpieces-disable max-lines-new-methods -- AST visitor pattern requires handling multiple node types
|
|
227
|
+
function visit(node) {
|
|
228
|
+
let methodName;
|
|
229
|
+
let startLine;
|
|
230
|
+
let endLine;
|
|
231
|
+
if (ts.isMethodDeclaration(node) && node.name) {
|
|
232
|
+
methodName = node.name.getText(sourceFile);
|
|
233
|
+
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
234
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
235
|
+
startLine = start.line + 1;
|
|
236
|
+
endLine = end.line + 1;
|
|
237
|
+
}
|
|
238
|
+
else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
239
|
+
methodName = node.name.getText(sourceFile);
|
|
240
|
+
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
241
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
242
|
+
startLine = start.line + 1;
|
|
243
|
+
endLine = end.line + 1;
|
|
244
|
+
}
|
|
245
|
+
else if (ts.isArrowFunction(node)) {
|
|
246
|
+
if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
|
|
247
|
+
methodName = node.parent.name.getText(sourceFile);
|
|
248
|
+
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
249
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
250
|
+
startLine = start.line + 1;
|
|
251
|
+
endLine = end.line + 1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (methodName && startLine !== undefined && endLine !== undefined) {
|
|
255
|
+
methods.push({ name: methodName, startLine, endLine });
|
|
256
|
+
}
|
|
257
|
+
ts.forEachChild(node, visit);
|
|
258
|
+
}
|
|
259
|
+
visit(sourceFile);
|
|
260
|
+
return methods;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Check if a line is within any method's range and if that method has changes.
|
|
264
|
+
*/
|
|
265
|
+
function isLineInChangedMethod(line, methods, changedLines, newMethodNames) {
|
|
266
|
+
for (const method of methods) {
|
|
267
|
+
if (line >= method.startLine && line <= method.endLine) {
|
|
268
|
+
// Check if this method is new or has changes
|
|
269
|
+
if (newMethodNames.has(method.name)) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
// Check if any line in the method range has changes
|
|
273
|
+
for (let l = method.startLine; l <= method.endLine; l++) {
|
|
274
|
+
if (changedLines.has(l)) {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Check if a line is within a new method.
|
|
284
|
+
*/
|
|
285
|
+
function isLineInNewMethod(line, methods, newMethodNames) {
|
|
286
|
+
for (const method of methods) {
|
|
287
|
+
if (line >= method.startLine && line <= method.endLine && newMethodNames.has(method.name)) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Parse diff to find newly added method signatures.
|
|
295
|
+
*/
|
|
296
|
+
function findNewMethodSignaturesInDiff(diffContent) {
|
|
297
|
+
const newMethods = new Set();
|
|
298
|
+
const lines = diffContent.split('\n');
|
|
299
|
+
const patterns = [
|
|
300
|
+
/^\+\s*(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/,
|
|
301
|
+
/^\+\s*(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s*)?\(/,
|
|
302
|
+
/^\+\s*(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s+)?function/,
|
|
303
|
+
/^\+\s*(?:(?:public|private|protected)\s+)?(?:static\s+)?(?:async\s+)?(\w+)\s*\(/,
|
|
304
|
+
];
|
|
305
|
+
for (const line of lines) {
|
|
306
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
307
|
+
for (const pattern of patterns) {
|
|
308
|
+
const match = line.match(pattern);
|
|
309
|
+
if (match) {
|
|
310
|
+
const methodName = match[1];
|
|
311
|
+
if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {
|
|
312
|
+
newMethods.add(methodName);
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return newMethods;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Find all inline type literals in a file.
|
|
323
|
+
*/
|
|
324
|
+
// webpieces-disable max-lines-new-methods -- AST traversal with visitor pattern
|
|
325
|
+
function findInlineTypesInFile(filePath, workspaceRoot) {
|
|
326
|
+
const fullPath = path.join(workspaceRoot, filePath);
|
|
327
|
+
if (!fs.existsSync(fullPath))
|
|
328
|
+
return [];
|
|
329
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
330
|
+
const fileLines = content.split('\n');
|
|
331
|
+
const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
|
|
332
|
+
const inlineTypes = [];
|
|
333
|
+
function visit(node) {
|
|
334
|
+
if (ts.isTypeLiteralNode(node)) {
|
|
335
|
+
if (!isInAllowedContext(node)) {
|
|
336
|
+
const pos = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
337
|
+
const line = pos.line + 1;
|
|
338
|
+
const column = pos.character + 1;
|
|
339
|
+
const context = getViolationContext(node, sourceFile);
|
|
340
|
+
const disabled = hasDisableComment(fileLines, line);
|
|
341
|
+
inlineTypes.push({
|
|
342
|
+
line,
|
|
343
|
+
column,
|
|
344
|
+
context,
|
|
345
|
+
hasDisableComment: disabled,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
ts.forEachChild(node, visit);
|
|
350
|
+
}
|
|
351
|
+
visit(sourceFile);
|
|
352
|
+
return inlineTypes;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Find violations in new methods only (NEW_METHODS mode).
|
|
356
|
+
*/
|
|
357
|
+
// webpieces-disable max-lines-new-methods -- File iteration with diff parsing and method matching
|
|
358
|
+
function findViolationsForNewMethods(workspaceRoot, changedFiles, base, head) {
|
|
359
|
+
const violations = [];
|
|
360
|
+
for (const file of changedFiles) {
|
|
361
|
+
const diff = getFileDiff(workspaceRoot, file, base, head);
|
|
362
|
+
const newMethodNames = findNewMethodSignaturesInDiff(diff);
|
|
363
|
+
if (newMethodNames.size === 0)
|
|
364
|
+
continue;
|
|
365
|
+
const methods = findMethodsInFile(file, workspaceRoot);
|
|
366
|
+
const inlineTypes = findInlineTypesInFile(file, workspaceRoot);
|
|
367
|
+
for (const inlineType of inlineTypes) {
|
|
368
|
+
if (inlineType.hasDisableComment)
|
|
369
|
+
continue;
|
|
370
|
+
if (!isLineInNewMethod(inlineType.line, methods, newMethodNames))
|
|
371
|
+
continue;
|
|
372
|
+
violations.push({
|
|
373
|
+
file,
|
|
374
|
+
line: inlineType.line,
|
|
375
|
+
column: inlineType.column,
|
|
376
|
+
context: inlineType.context,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return violations;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Find violations in new and modified methods (MODIFIED_AND_NEW_METHODS mode).
|
|
384
|
+
*/
|
|
385
|
+
// webpieces-disable max-lines-new-methods -- Combines new method detection with change detection
|
|
386
|
+
function findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head) {
|
|
387
|
+
const violations = [];
|
|
388
|
+
for (const file of changedFiles) {
|
|
389
|
+
const diff = getFileDiff(workspaceRoot, file, base, head);
|
|
390
|
+
const newMethodNames = findNewMethodSignaturesInDiff(diff);
|
|
391
|
+
const changedLines = getChangedLineNumbers(diff);
|
|
392
|
+
const methods = findMethodsInFile(file, workspaceRoot);
|
|
393
|
+
const inlineTypes = findInlineTypesInFile(file, workspaceRoot);
|
|
394
|
+
for (const inlineType of inlineTypes) {
|
|
395
|
+
if (inlineType.hasDisableComment)
|
|
396
|
+
continue;
|
|
397
|
+
if (!isLineInChangedMethod(inlineType.line, methods, changedLines, newMethodNames))
|
|
398
|
+
continue;
|
|
399
|
+
violations.push({
|
|
400
|
+
file,
|
|
401
|
+
line: inlineType.line,
|
|
402
|
+
column: inlineType.column,
|
|
403
|
+
context: inlineType.context,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return violations;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Find all violations in modified files (MODIFIED_FILES mode).
|
|
411
|
+
*/
|
|
412
|
+
function findViolationsForModifiedFiles(workspaceRoot, changedFiles) {
|
|
413
|
+
const violations = [];
|
|
414
|
+
for (const file of changedFiles) {
|
|
415
|
+
const inlineTypes = findInlineTypesInFile(file, workspaceRoot);
|
|
416
|
+
for (const inlineType of inlineTypes) {
|
|
417
|
+
if (inlineType.hasDisableComment)
|
|
418
|
+
continue;
|
|
419
|
+
violations.push({
|
|
420
|
+
file,
|
|
421
|
+
line: inlineType.line,
|
|
422
|
+
column: inlineType.column,
|
|
423
|
+
context: inlineType.context,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return violations;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Find all violations in all files (ALL mode).
|
|
431
|
+
*/
|
|
432
|
+
function findViolationsForAll(workspaceRoot) {
|
|
433
|
+
const allFiles = getAllTypeScriptFiles(workspaceRoot);
|
|
434
|
+
return findViolationsForModifiedFiles(workspaceRoot, allFiles);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Auto-detect the base branch by finding the merge-base with origin/main.
|
|
438
|
+
*/
|
|
439
|
+
function detectBase(workspaceRoot) {
|
|
440
|
+
try {
|
|
441
|
+
const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD origin/main', {
|
|
442
|
+
cwd: workspaceRoot,
|
|
443
|
+
encoding: 'utf-8',
|
|
444
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
445
|
+
}).trim();
|
|
446
|
+
if (mergeBase) {
|
|
447
|
+
return mergeBase;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch {
|
|
451
|
+
try {
|
|
452
|
+
const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD main', {
|
|
453
|
+
cwd: workspaceRoot,
|
|
454
|
+
encoding: 'utf-8',
|
|
455
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
456
|
+
}).trim();
|
|
457
|
+
if (mergeBase) {
|
|
458
|
+
return mergeBase;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
// Ignore
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Report violations to console.
|
|
469
|
+
*/
|
|
470
|
+
function reportViolations(violations, mode) {
|
|
471
|
+
console.error('');
|
|
472
|
+
console.error('❌ Inline type literals found! Use named types instead.');
|
|
473
|
+
console.error('');
|
|
474
|
+
console.error('📚 Named types improve code clarity and reusability:');
|
|
475
|
+
console.error('');
|
|
476
|
+
console.error(' BAD: function foo(arg: { x: number }) { }');
|
|
477
|
+
console.error(' GOOD: type MyConfig = { x: number };');
|
|
478
|
+
console.error(' function foo(arg: MyConfig) { }');
|
|
479
|
+
console.error('');
|
|
480
|
+
console.error(' BAD: type Nullable = { x: number } | null;');
|
|
481
|
+
console.error(' GOOD: type MyData = { x: number };');
|
|
482
|
+
console.error(' type Nullable = MyData | null;');
|
|
483
|
+
console.error('');
|
|
484
|
+
for (const v of violations) {
|
|
485
|
+
console.error(` ❌ ${v.file}:${v.line}:${v.column}`);
|
|
486
|
+
console.error(` ${v.context}`);
|
|
487
|
+
}
|
|
488
|
+
console.error('');
|
|
489
|
+
console.error(' To fix: Extract inline types to named type aliases or interfaces');
|
|
490
|
+
console.error('');
|
|
491
|
+
console.error(' Escape hatch (use sparingly):');
|
|
492
|
+
console.error(' // webpieces-disable no-inline-types -- [your reason]');
|
|
493
|
+
console.error('');
|
|
494
|
+
console.error(` Current mode: ${mode}`);
|
|
495
|
+
console.error('');
|
|
496
|
+
}
|
|
497
|
+
async function runExecutor(options, context) {
|
|
498
|
+
const workspaceRoot = context.root;
|
|
499
|
+
const mode = options.mode ?? 'OFF';
|
|
500
|
+
if (mode === 'OFF') {
|
|
501
|
+
console.log('\n⏭️ Skipping no-inline-types validation (mode: OFF)');
|
|
502
|
+
console.log('');
|
|
503
|
+
return { success: true };
|
|
504
|
+
}
|
|
505
|
+
console.log('\n📏 Validating No Inline Types\n');
|
|
506
|
+
console.log(` Mode: ${mode}`);
|
|
507
|
+
let violations = [];
|
|
508
|
+
if (mode === 'ALL') {
|
|
509
|
+
console.log(' Scope: All tracked TypeScript files');
|
|
510
|
+
console.log('');
|
|
511
|
+
violations = findViolationsForAll(workspaceRoot);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
let base = process.env['NX_BASE'];
|
|
515
|
+
const head = process.env['NX_HEAD'];
|
|
516
|
+
if (!base) {
|
|
517
|
+
base = detectBase(workspaceRoot) ?? undefined;
|
|
518
|
+
if (!base) {
|
|
519
|
+
console.log('\n⏭️ Skipping no-inline-types validation (could not detect base branch)');
|
|
520
|
+
console.log('');
|
|
521
|
+
return { success: true };
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
console.log(` Base: ${base}`);
|
|
525
|
+
console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
|
|
526
|
+
console.log('');
|
|
527
|
+
const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);
|
|
528
|
+
if (changedFiles.length === 0) {
|
|
529
|
+
console.log('✅ No TypeScript files changed');
|
|
530
|
+
return { success: true };
|
|
531
|
+
}
|
|
532
|
+
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
533
|
+
if (mode === 'NEW_METHODS') {
|
|
534
|
+
violations = findViolationsForNewMethods(workspaceRoot, changedFiles, base, head);
|
|
535
|
+
}
|
|
536
|
+
else if (mode === 'MODIFIED_AND_NEW_METHODS') {
|
|
537
|
+
violations = findViolationsForModifiedAndNewMethods(workspaceRoot, changedFiles, base, head);
|
|
538
|
+
}
|
|
539
|
+
else if (mode === 'MODIFIED_FILES') {
|
|
540
|
+
violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (violations.length === 0) {
|
|
544
|
+
console.log('✅ No inline type literals found');
|
|
545
|
+
return { success: true };
|
|
546
|
+
}
|
|
547
|
+
reportViolations(violations, mode);
|
|
548
|
+
return { success: false };
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-no-inline-types/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;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AO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,eAAe,YAAY,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAErE,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YACzB,UAAU,GAAG,2BAA2B,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACtF,CAAC;aAAM,IAAI,IAAI,KAAK,0BAA0B,EAAE,CAAC;YAC7C,UAAU,GAAG,sCAAsC,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACjG,CAAC;aAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACnC,UAAU,GAAG,8BAA8B,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;QAC7E,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAC/C,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 No Inline Types Executor\n *\n * Validates that inline type literals are not used - prefer named types/interfaces/classes.\n * Instead of anonymous object types, use named types for clarity and reusability:\n *\n * BAD: function foo(arg: { x: number }) { }\n * GOOD: function foo(arg: MyConfig) { }\n *\n * BAD: type Nullable = { x: number } | null;\n * GOOD: type MyData = { x: number }; type Nullable = MyData | null;\n *\n * Modes:\n * - OFF: Skip validation entirely\n * - NEW_METHODS: Only validate inline types in new methods (detected via git diff)\n * - MODIFIED_AND_NEW_METHODS: Validate in new methods + methods with changes in their line range\n * - MODIFIED_FILES: Validate all inline types in modified files\n * - ALL: Validate all inline types in all TypeScript files\n *\n * Escape hatch: Add webpieces-disable no-inline-types 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 NoInlineTypesMode = 'OFF' | 'NEW_METHODS' | 'MODIFIED_AND_NEW_METHODS' | 'MODIFIED_FILES' | 'ALL';\n\nexport interface ValidateNoInlineTypesOptions {\n mode?: NoInlineTypesMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface InlineTypeViolation {\n file: string;\n line: number;\n column: number;\n context: string;\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 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 line contains a webpieces-disable comment for no-inline-types.\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('no-inline-types')) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Check if a TypeLiteral node is in an allowed context.\n * Only allowed if the DIRECT parent is a TypeAliasDeclaration.\n */\nfunction isInAllowedContext(node: ts.TypeLiteralNode): boolean {\n const parent = node.parent;\n // Only allowed if it's the DIRECT body of a type alias\n if (ts.isTypeAliasDeclaration(parent)) {\n return true;\n }\n return false;\n}\n\n/**\n * Get a description of the context where the inline type appears.\n */\n// webpieces-disable max-lines-new-methods -- Context detection requires checking many AST node types\nfunction getViolationContext(node: ts.TypeLiteralNode, sourceFile: ts.SourceFile): string {\n let current: ts.Node = node;\n while (current.parent) {\n const parent = current.parent;\n if (ts.isParameter(parent)) {\n return 'inline parameter type';\n }\n if (ts.isFunctionDeclaration(parent) || ts.isMethodDeclaration(parent) || ts.isArrowFunction(parent)) {\n if (parent.type === current) {\n return 'inline return type';\n }\n }\n if (ts.isVariableDeclaration(parent)) {\n return 'inline variable type';\n }\n if (ts.isPropertyDeclaration(parent) || ts.isPropertySignature(parent)) {\n if (parent.type === current) {\n return 'inline property type';\n }\n // Check if it's nested inside another type literal\n let ancestor: ts.Node | undefined = parent.parent;\n while (ancestor) {\n if (ts.isTypeLiteralNode(ancestor)) {\n return 'nested inline type';\n }\n if (ts.isTypeAliasDeclaration(ancestor)) {\n return 'nested inline type in type alias';\n }\n ancestor = ancestor.parent;\n }\n }\n if (ts.isUnionTypeNode(parent) || ts.isIntersectionTypeNode(parent)) {\n return 'inline type in union/intersection';\n }\n if (ts.isTypeReferenceNode(parent.parent) && ts.isTypeNode(parent)) {\n return 'inline type in generic argument';\n }\n current = parent;\n }\n return 'inline type literal';\n}\n\ninterface MethodInfo {\n name: string;\n startLine: number;\n endLine: number;\n}\n\n/**\n * Find all methods/functions in a file with their line ranges.\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 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\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 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({ name: methodName, startLine, endLine });\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return methods;\n}\n\n/**\n * Check if a line is within any method's range and if that method has changes.\n */\nfunction isLineInChangedMethod(\n line: number,\n methods: MethodInfo[],\n changedLines: Set<number>,\n newMethodNames: Set<string>\n): boolean {\n for (const method of methods) {\n if (line >= method.startLine && line <= method.endLine) {\n // Check if this method is new or has changes\n if (newMethodNames.has(method.name)) {\n return true;\n }\n // Check if any line in the method range has changes\n for (let l = method.startLine; l <= method.endLine; l++) {\n if (changedLines.has(l)) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\n/**\n * Check if a line is within a new method.\n */\nfunction isLineInNewMethod(line: number, methods: MethodInfo[], newMethodNames: Set<string>): boolean {\n for (const method of methods) {\n if (line >= method.startLine && line <= method.endLine && newMethodNames.has(method.name)) {\n return true;\n }\n }\n return false;\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\ninterface InlineTypeInfo {\n line: number;\n column: number;\n context: string;\n hasDisableComment: boolean;\n}\n\n/**\n * Find all inline type literals in a file.\n */\n// webpieces-disable max-lines-new-methods -- AST traversal with visitor pattern\nfunction findInlineTypesInFile(filePath: string, workspaceRoot: string): InlineTypeInfo[] {\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 inlineTypes: InlineTypeInfo[] = [];\n\n function visit(node: ts.Node): void {\n if (ts.isTypeLiteralNode(node)) {\n if (!isInAllowedContext(node)) {\n const pos = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = pos.line + 1;\n const column = pos.character + 1;\n const context = getViolationContext(node, sourceFile);\n const disabled = hasDisableComment(fileLines, line);\n\n inlineTypes.push({\n line,\n column,\n context,\n hasDisableComment: disabled,\n });\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return inlineTypes;\n}\n\n/**\n * Find violations in new methods only (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): InlineTypeViolation[] {\n const violations: InlineTypeViolation[] = [];\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 const inlineTypes = findInlineTypesInFile(file, workspaceRoot);\n\n for (const inlineType of inlineTypes) {\n if (inlineType.hasDisableComment) continue;\n if (!isLineInNewMethod(inlineType.line, methods, newMethodNames)) continue;\n\n violations.push({\n file,\n line: inlineType.line,\n column: inlineType.column,\n context: inlineType.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find violations in new and modified methods (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): InlineTypeViolation[] {\n const violations: InlineTypeViolation[] = [];\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 const inlineTypes = findInlineTypesInFile(file, workspaceRoot);\n\n for (const inlineType of inlineTypes) {\n if (inlineType.hasDisableComment) continue;\n if (!isLineInChangedMethod(inlineType.line, methods, changedLines, newMethodNames)) continue;\n\n violations.push({\n file,\n line: inlineType.line,\n column: inlineType.column,\n context: inlineType.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all violations in modified files (MODIFIED_FILES mode).\n */\nfunction findViolationsForModifiedFiles(workspaceRoot: string, changedFiles: string[]): InlineTypeViolation[] {\n const violations: InlineTypeViolation[] = [];\n\n for (const file of changedFiles) {\n const inlineTypes = findInlineTypesInFile(file, workspaceRoot);\n\n for (const inlineType of inlineTypes) {\n if (inlineType.hasDisableComment) continue;\n\n violations.push({\n file,\n line: inlineType.line,\n column: inlineType.column,\n context: inlineType.context,\n });\n }\n }\n\n return violations;\n}\n\n/**\n * Find all violations in all files (ALL mode).\n */\nfunction findViolationsForAll(workspaceRoot: string): InlineTypeViolation[] {\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: InlineTypeViolation[], mode: NoInlineTypesMode): void {\n console.error('');\n console.error('❌ Inline type literals found! Use named types instead.');\n console.error('');\n console.error('📚 Named types improve code clarity and reusability:');\n console.error('');\n console.error(' BAD: function foo(arg: { x: number }) { }');\n console.error(' GOOD: type MyConfig = { x: number };');\n console.error(' function foo(arg: MyConfig) { }');\n console.error('');\n console.error(' BAD: type Nullable = { x: number } | null;');\n console.error(' GOOD: type MyData = { x: number };');\n console.error(' type Nullable = MyData | null;');\n console.error('');\n\n for (const v of violations) {\n console.error(` ❌ ${v.file}:${v.line}:${v.column}`);\n console.error(` ${v.context}`);\n }\n console.error('');\n\n console.error(' To fix: Extract inline types to named type aliases or interfaces');\n console.error('');\n console.error(' Escape hatch (use sparingly):');\n console.error(' // webpieces-disable no-inline-types -- [your reason]');\n console.error('');\n console.error(` Current mode: ${mode}`);\n console.error('');\n}\n\nexport default async function runExecutor(\n options: ValidateNoInlineTypesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const mode: NoInlineTypesMode = options.mode ?? 'OFF';\n\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping no-inline-types validation (mode: OFF)');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n📏 Validating No Inline Types\\n');\n console.log(` Mode: ${mode}`);\n\n let violations: InlineTypeViolation[] = [];\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 no-inline-types 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('✅ No inline type literals found');\n return { success: true };\n }\n\n reportViolations(violations, mode);\n\n return { success: false };\n}\n"]}
|