@webpieces/dev-config 0.2.63 → 0.2.65
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-modified-files/executor.d.ts +2 -1
- package/architecture/executors/validate-modified-files/executor.js +17 -13
- package/architecture/executors/validate-modified-files/executor.js.map +1 -1
- package/architecture/executors/validate-modified-files/executor.ts +21 -14
- package/architecture/executors/validate-modified-files/schema.json +5 -4
- package/architecture/executors/validate-modified-methods/executor.d.ts +2 -0
- package/architecture/executors/validate-modified-methods/executor.js +80 -95
- package/architecture/executors/validate-modified-methods/executor.js.map +1 -1
- package/architecture/executors/validate-modified-methods/executor.ts +88 -96
- package/architecture/executors/validate-modified-methods/schema.json +6 -0
- package/architecture/executors/validate-new-methods/executor.d.ts +2 -0
- package/architecture/executors/validate-new-methods/executor.js +7 -0
- package/architecture/executors/validate-new-methods/executor.js.map +1 -1
- package/architecture/executors/validate-new-methods/executor.ts +11 -0
- package/architecture/executors/validate-new-methods/schema.json +6 -0
- package/package.json +1 -1
- package/plugin.js +13 -13
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* The disable expires after 1 month from the date specified.
|
|
14
14
|
*/
|
|
15
15
|
import type { ExecutorContext } from '@nx/devkit';
|
|
16
|
+
export type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';
|
|
16
17
|
export interface ValidateModifiedFilesOptions {
|
|
17
18
|
max?: number;
|
|
18
|
-
|
|
19
|
+
mode?: ValidationMode;
|
|
19
20
|
}
|
|
20
21
|
export interface ExecutorResult {
|
|
21
22
|
success: boolean;
|
|
@@ -287,7 +287,7 @@ function checkDisableComment(content) {
|
|
|
287
287
|
* Count lines in a file and check for violations
|
|
288
288
|
*/
|
|
289
289
|
// webpieces-disable max-lines-new-methods -- File iteration with disable checking logic
|
|
290
|
-
function findViolations(workspaceRoot, changedFiles, maxLines,
|
|
290
|
+
function findViolations(workspaceRoot, changedFiles, maxLines, mode) {
|
|
291
291
|
const violations = [];
|
|
292
292
|
for (const file of changedFiles) {
|
|
293
293
|
const fullPath = path.join(workspaceRoot, file);
|
|
@@ -298,8 +298,8 @@ function findViolations(workspaceRoot, changedFiles, maxLines, forceLimit) {
|
|
|
298
298
|
// Skip files under the limit
|
|
299
299
|
if (lineCount <= maxLines)
|
|
300
300
|
continue;
|
|
301
|
-
// When
|
|
302
|
-
if (
|
|
301
|
+
// When mode is STRICT, ignore all disable comments
|
|
302
|
+
if (mode === 'STRICT') {
|
|
303
303
|
violations.push({ file, lines: lineCount });
|
|
304
304
|
continue;
|
|
305
305
|
}
|
|
@@ -374,7 +374,7 @@ function getTodayDateString() {
|
|
|
374
374
|
* Report violations to console
|
|
375
375
|
*/
|
|
376
376
|
// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections
|
|
377
|
-
function reportViolations(violations, maxLines,
|
|
377
|
+
function reportViolations(violations, maxLines, mode) {
|
|
378
378
|
console.error('');
|
|
379
379
|
console.error('❌ YOU MUST FIX THIS AND NOT be more than ' + maxLines + ' lines of code per file');
|
|
380
380
|
console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');
|
|
@@ -398,8 +398,8 @@ function reportViolations(violations, maxLines, forceLimit) {
|
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
console.error('');
|
|
401
|
-
// Only show escape hatch instructions when
|
|
402
|
-
if (
|
|
401
|
+
// Only show escape hatch instructions when mode is not STRICT
|
|
402
|
+
if (mode !== 'STRICT') {
|
|
403
403
|
console.error(' You can disable this error, but you will be forced to fix again in 1 month');
|
|
404
404
|
console.error(' since 99% of files can be less than ' + maxLines + ' lines of code.');
|
|
405
405
|
console.error('');
|
|
@@ -408,7 +408,7 @@ function reportViolations(violations, maxLines, forceLimit) {
|
|
|
408
408
|
console.error('');
|
|
409
409
|
}
|
|
410
410
|
else {
|
|
411
|
-
console.error(' ⚠️
|
|
411
|
+
console.error(' ⚠️ validationMode is STRICT - disable comments are NOT allowed.');
|
|
412
412
|
console.error(' You MUST refactor to reduce file size.');
|
|
413
413
|
console.error('');
|
|
414
414
|
}
|
|
@@ -416,7 +416,13 @@ function reportViolations(violations, maxLines, forceLimit) {
|
|
|
416
416
|
async function runExecutor(options, context) {
|
|
417
417
|
const workspaceRoot = context.root;
|
|
418
418
|
const maxLines = options.max ?? 900;
|
|
419
|
-
const
|
|
419
|
+
const mode = options.mode ?? 'NORMAL';
|
|
420
|
+
// Skip validation entirely if mode is OFF
|
|
421
|
+
if (mode === 'OFF') {
|
|
422
|
+
console.log('\n⏭️ Skipping modified files validation (validationMode: OFF)');
|
|
423
|
+
console.log('');
|
|
424
|
+
return { success: true };
|
|
425
|
+
}
|
|
420
426
|
let base = process.env['NX_BASE'];
|
|
421
427
|
if (!base) {
|
|
422
428
|
base = detectBase(workspaceRoot) ?? undefined;
|
|
@@ -434,9 +440,7 @@ async function runExecutor(options, context) {
|
|
|
434
440
|
console.log(` Base: ${base}`);
|
|
435
441
|
console.log(' Comparing to: working tree (includes uncommitted changes)');
|
|
436
442
|
console.log(` Max lines for modified files: ${maxLines}`);
|
|
437
|
-
|
|
438
|
-
console.log(' Force limit: ENABLED (disable comments will be ignored)');
|
|
439
|
-
}
|
|
443
|
+
console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored)' : ''}`);
|
|
440
444
|
console.log('');
|
|
441
445
|
try {
|
|
442
446
|
const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base);
|
|
@@ -445,13 +449,13 @@ async function runExecutor(options, context) {
|
|
|
445
449
|
return { success: true };
|
|
446
450
|
}
|
|
447
451
|
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
448
|
-
const violations = findViolations(workspaceRoot, changedFiles, maxLines,
|
|
452
|
+
const violations = findViolations(workspaceRoot, changedFiles, maxLines, mode);
|
|
449
453
|
if (violations.length === 0) {
|
|
450
454
|
console.log('✅ All modified files are under ' + maxLines + ' lines');
|
|
451
455
|
return { success: true };
|
|
452
456
|
}
|
|
453
457
|
writeTmpInstructions(workspaceRoot);
|
|
454
|
-
reportViolations(violations, maxLines,
|
|
458
|
+
reportViolations(violations, maxLines, mode);
|
|
455
459
|
return { success: false };
|
|
456
460
|
}
|
|
457
461
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-modified-files/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAwcH,8BA0DC;;AA/fD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAkB7B,MAAM,OAAO,GAAG,eAAe,CAAC;AAChC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuK5B,CAAC;AAEF;;GAEG;AACH,SAAS,oBAAoB,CAAC,aAAqB;IAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAE9C,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAE/C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,aAAqB,EAAE,IAAY;IAClE,IAAI,CAAC;QACD,gEAAgE;QAChE,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,IAAI,oBAAoB,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AAC,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,MAAM,UAAU,GAAG,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAErF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,iCAAiC,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;YACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACpC,gBAAgB,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QACnD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACpE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Modified Files Executor\n *\n * Validates that modified files don't exceed a maximum line count (default 900).\n * This encourages keeping files small and focused - when you touch a file,\n * you must bring it under the limit.\n *\n * Usage:\n * nx affected --target=validate-modified-files --base=origin/main\n *\n * Escape hatch: Add webpieces-disable max-lines-modified-files comment with date and justification\n * Format: // webpieces-disable max-lines-modified-files 2025/01/15 -- [reason]\n * The disable expires after 1 month from the date specified.\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport interface ValidateModifiedFilesOptions {\n max?: number;\n forceLimit?: boolean;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface FileViolation {\n file: string;\n lines: number;\n expiredDisable?: boolean;\n expiredDate?: string;\n}\n\nconst TMP_DIR = 'tmp/webpieces';\nconst TMP_MD_FILE = 'webpieces.filesize.md';\n\nconst FILESIZE_DOC_CONTENT = `# AI Agent Instructions: File Too Long\n\n**READ THIS FILE to fix files that are too long**\n\n## Core Principle\n\nWith **stateless systems + dependency injection, refactor is trivial**.\nPick a method or a few and move to new class XXXXX, then inject XXXXX\ninto all users of those methods via the constructor.\nDelete those methods from original class.\n\n**99% of files can be less than the configured max lines of code.**\n\nFiles should contain a SINGLE COHESIVE UNIT.\n- One class per file (Java convention)\n- If class is too large, extract child responsibilities\n- Use dependency injection to compose functionality\n\n## Command: Reduce File Size\n\n### Step 1: Check for Multiple Classes\nIf the file contains multiple classes, **SEPARATE each class into its own file**.\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (multiple classes)\nexport class UserController { /* ... */ }\nexport class UserValidator { /* ... */ }\nexport class UserNotifier { /* ... */ }\n\n// GOOD: Three separate files\n// UserController.ts\nexport class UserController { /* ... */ }\n\n// UserValidator.ts\nexport class UserValidator { /* ... */ }\n\n// UserNotifier.ts\nexport class UserNotifier { /* ... */ }\n\\`\\`\\`\n\n### Step 2: Extract Child Responsibilities (if single class is too large)\n\n#### Pattern: Create New Service Class with Dependency Injection\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (800 lines, single class)\n@provideSingleton()\n@Controller()\nexport class UserController {\n // 200 lines: CRUD operations\n // 300 lines: validation logic\n // 200 lines: notification logic\n // 100 lines: analytics logic\n}\n\n// GOOD: Extract validation service\n// 1. Create UserValidationService.ts\n@provideSingleton()\nexport class UserValidationService {\n validateUserData(data: UserData): ValidationResult {\n // 300 lines of validation logic moved here\n }\n\n validateEmail(email: string): boolean { /* ... */ }\n validatePassword(password: string): boolean { /* ... */ }\n}\n\n// 2. Inject into UserController.ts\n@provideSingleton()\n@Controller()\nexport class UserController {\n constructor(\n @inject(TYPES.UserValidationService)\n private validator: UserValidationService\n ) {}\n\n async createUser(data: UserData): Promise<User> {\n const validation = this.validator.validateUserData(data);\n if (!validation.isValid) {\n throw new ValidationError(validation.errors);\n }\n // ... rest of logic\n }\n}\n\\`\\`\\`\n\n## AI Agent Action Steps\n\n1. **ANALYZE** the file structure:\n - Count classes (if >1, separate immediately)\n - Identify logical responsibilities within single class\n\n2. **IDENTIFY** \"child code\" to extract:\n - Validation logic -> ValidationService\n - Notification logic -> NotificationService\n - Data transformation -> TransformerService\n - External API calls -> ApiService\n - Business rules -> RulesEngine\n\n3. **CREATE** new service file(s):\n - Start with temporary name: \\`XXXX.ts\\` or \\`ChildService.ts\\`\n - Add \\`@provideSingleton()\\` decorator\n - Move child methods to new class\n\n4. **UPDATE** dependency injection:\n - Add to \\`TYPES\\` constants (if using symbol-based DI)\n - Inject new service into original class constructor\n - Replace direct method calls with \\`this.serviceName.method()\\`\n\n5. **RENAME** extracted file:\n - Read the extracted code to understand its purpose\n - Rename \\`XXXX.ts\\` to logical name (e.g., \\`UserValidationService.ts\\`)\n\n6. **VERIFY** file sizes:\n - Original file should now be under the limit\n - Each extracted file should be under the limit\n - If still too large, extract more services\n\n## Examples of Child Responsibilities to Extract\n\n| If File Contains | Extract To | Pattern |\n|-----------------|------------|---------|\n| Validation logic (200+ lines) | \\`XValidator.ts\\` or \\`XValidationService.ts\\` | Singleton service |\n| Notification logic (150+ lines) | \\`XNotifier.ts\\` or \\`XNotificationService.ts\\` | Singleton service |\n| Data transformation (200+ lines) | \\`XTransformer.ts\\` | Singleton service |\n| External API calls (200+ lines) | \\`XApiClient.ts\\` | Singleton service |\n| Complex business rules (300+ lines) | \\`XRulesEngine.ts\\` | Singleton service |\n| Database queries (200+ lines) | \\`XRepository.ts\\` | Singleton service |\n\n## WebPieces Dependency Injection Pattern\n\n\\`\\`\\`typescript\n// 1. Define service with @provideSingleton\nimport { provideSingleton } from '@webpieces/http-routing';\n\n@provideSingleton()\nexport class MyService {\n doSomething(): void { /* ... */ }\n}\n\n// 2. Inject into consumer\nimport { inject } from 'inversify';\nimport { TYPES } from './types';\n\n@provideSingleton()\n@Controller()\nexport class MyController {\n constructor(\n @inject(TYPES.MyService) private service: MyService\n ) {}\n}\n\\`\\`\\`\n\n## Escape Hatch\n\nIf refactoring is genuinely not feasible (generated files, complex algorithms, etc.),\nadd a disable comment at the TOP of the file (within first 5 lines) with a DATE:\n\n\\`\\`\\`typescript\n// webpieces-disable max-lines-modified-files 2025/01/15 -- Complex generated file, refactoring would break generation\n\\`\\`\\`\n\n**IMPORTANT**: The date format is yyyy/mm/dd. The disable will EXPIRE after 1 month from this date.\nAfter expiration, you must either fix the file or update the date to get another month.\nThis ensures that disable comments are reviewed periodically.\n\nRemember: Find the \"child code\" and pull it down into a new class. Once moved, the code's purpose becomes clear, making it easy to rename to a logical name.\n`;\n\n/**\n * Write the instructions documentation to tmp directory\n */\nfunction writeTmpInstructions(workspaceRoot: string): string {\n const tmpDir = path.join(workspaceRoot, TMP_DIR);\n const mdPath = path.join(tmpDir, TMP_MD_FILE);\n\n fs.mkdirSync(tmpDir, { recursive: true });\n fs.writeFileSync(mdPath, FILESIZE_DOC_CONTENT);\n\n return mdPath;\n}\n\n/**\n * Get changed TypeScript files between base and working tree.\n * Uses `git diff base` (no three-dots) to match what `nx affected` does -\n * this includes both committed and uncommitted changes in one diff.\n */\nfunction getChangedTypeScriptFiles(workspaceRoot: string, base: string): string[] {\n try {\n // Use two-dot diff (base to working tree) - same as nx affected\n const output = execSync(`git diff --name-only ${base} -- '*.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 * Parse a date string in yyyy/mm/dd format and return a Date object.\n * Returns null if the format is invalid.\n */\nfunction parseDisableDate(dateStr: string): Date | null {\n // Match yyyy/mm/dd format\n const match = dateStr.match(/^(\\d{4})\\/(\\d{2})\\/(\\d{2})$/);\n if (!match) return null;\n\n const year = parseInt(match[1], 10);\n const month = parseInt(match[2], 10) - 1; // JS months are 0-indexed\n const day = parseInt(match[3], 10);\n\n const date = new Date(year, month, day);\n\n // Validate the date is valid (e.g., not Feb 30)\n if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {\n return null;\n }\n\n return date;\n}\n\n/**\n * Check if a date is within the last month (not expired).\n */\nfunction isDateWithinMonth(date: Date): boolean {\n const now = new Date();\n const oneMonthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());\n return date >= oneMonthAgo;\n}\n\ninterface DisableStatus {\n hasDisable: boolean;\n isValid: boolean;\n isExpired: boolean;\n date?: string;\n}\n\n/**\n * Check if a file has a valid, non-expired disable comment at the top (within first 5 lines).\n * Returns status object with details about the disable comment.\n */\n// webpieces-disable max-lines-new-methods -- Date validation logic requires checking multiple conditions\nfunction checkDisableComment(content: string): DisableStatus {\n const lines = content.split('\\n').slice(0, 5);\n\n for (const line of lines) {\n if (line.includes('webpieces-disable') && line.includes('max-lines-modified-files')) {\n // Found disable comment, now check for date\n // Format: // webpieces-disable max-lines-modified-files yyyy/mm/dd -- reason\n const dateMatch = line.match(/max-lines-modified-files\\s+(\\d{4}\\/\\d{2}\\/\\d{2}|XXXX\\/XX\\/XX)/);\n\n if (!dateMatch) {\n // No date found - invalid disable comment\n return { hasDisable: true, isValid: false, isExpired: false };\n }\n\n const dateStr = dateMatch[1];\n\n // Secret permanent disable\n if (dateStr === 'XXXX/XX/XX') {\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n\n const date = parseDisableDate(dateStr);\n if (!date) {\n // Invalid date format\n return { hasDisable: true, isValid: false, isExpired: false, date: dateStr };\n }\n\n if (!isDateWithinMonth(date)) {\n // Date is expired (older than 1 month)\n return { hasDisable: true, isValid: true, isExpired: true, date: dateStr };\n }\n\n // Valid and not expired\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n }\n\n return { hasDisable: false, isValid: false, isExpired: false };\n}\n\n/**\n * Count lines in a file and check for violations\n */\n// webpieces-disable max-lines-new-methods -- File iteration with disable checking logic\nfunction findViolations(workspaceRoot: string, changedFiles: string[], maxLines: number, forceLimit: boolean): FileViolation[] {\n const violations: FileViolation[] = [];\n\n for (const file of changedFiles) {\n const fullPath = path.join(workspaceRoot, file);\n\n if (!fs.existsSync(fullPath)) continue;\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const lineCount = content.split('\\n').length;\n\n // Skip files under the limit\n if (lineCount <= maxLines) continue;\n\n // When forceLimit is true, ignore all disable comments\n if (forceLimit) {\n violations.push({ file, lines: lineCount });\n continue;\n }\n\n // Check for disable comment\n const disableStatus = checkDisableComment(content);\n\n if (disableStatus.hasDisable) {\n if (disableStatus.isValid && !disableStatus.isExpired) {\n // Valid, non-expired disable - skip this file\n continue;\n }\n\n if (disableStatus.isExpired) {\n // Expired disable - report as violation with expired info\n violations.push({\n file,\n lines: lineCount,\n expiredDisable: true,\n expiredDate: disableStatus.date,\n });\n continue;\n }\n\n // Invalid disable (missing/bad date) - fall through to report as violation\n }\n\n violations.push({\n file,\n lines: lineCount,\n });\n }\n\n return violations;\n}\n\n/**\n * Auto-detect the base branch by finding the merge-base with origin/main.\n */\nfunction detectBase(workspaceRoot: string): string | null {\n try {\n const mergeBase = execSync('git merge-base HEAD origin/main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n try {\n const mergeBase = execSync('git merge-base HEAD main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n // Ignore\n }\n }\n return null;\n}\n\n/**\n * Get today's date in yyyy/mm/dd format for error messages\n */\nfunction getTodayDateString(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}/${month}/${day}`;\n}\n\n/**\n * Report violations to console\n */\n// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections\nfunction reportViolations(violations: FileViolation[], maxLines: number, forceLimit: boolean): void {\n console.error('');\n console.error('❌ YOU MUST FIX THIS AND NOT be more than ' + maxLines + ' lines of code per file');\n console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');\n console.error('');\n console.error('📚 With stateless systems + dependency injection, refactor is trivial:');\n console.error(' Pick a method or a few and move to new class XXXXX, then inject XXXXX');\n console.error(' into all users of those methods via the constructor.');\n console.error(' Delete those methods from original class.');\n console.error(' 99% of files can be less than ' + maxLines + ' lines of code.');\n console.error('');\n console.error('⚠️ *** READ tmp/webpieces/webpieces.filesize.md for detailed guidance on how to fix this easily *** ⚠️');\n console.error('');\n\n for (const v of violations) {\n if (v.expiredDisable) {\n console.error(` ❌ ${v.file} (${v.lines} lines, max: ${maxLines})`);\n console.error(` ⏰ EXPIRED DISABLE: Your disable comment dated ${v.expiredDate} has expired (>1 month old).`);\n console.error(` You must either FIX the file or UPDATE the date to get another month.`);\n } else {\n console.error(` ❌ ${v.file} (${v.lines} lines, max: ${maxLines})`);\n }\n }\n console.error('');\n\n // Only show escape hatch instructions when forceLimit is not enabled\n if (!forceLimit) {\n console.error(' You can disable this error, but you will be forced to fix again in 1 month');\n console.error(' since 99% of files can be less than ' + maxLines + ' lines of code.');\n console.error('');\n console.error(' Use escape with DATE (expires in 1 month):');\n console.error(` // webpieces-disable max-lines-modified-files ${getTodayDateString()} -- [your reason]`);\n console.error('');\n } else {\n console.error(' ⚠️ forceModifiedFilesLimit is enabled - disable comments are NOT allowed.');\n console.error(' You MUST refactor to reduce file size.');\n console.error('');\n }\n}\n\nexport default async function runExecutor(\n options: ValidateModifiedFilesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const maxLines = options.max ?? 900;\n const forceLimit = options.forceLimit ?? false;\n\n let base = process.env['NX_BASE'];\n\n if (!base) {\n base = detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n⏭️ Skipping modified files validation (could not detect base branch)');\n console.log(' To run explicitly: nx affected --target=validate-modified-files --base=origin/main');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n📏 Validating Modified File Sizes (auto-detected base)\\n');\n } else {\n console.log('\\n📏 Validating Modified File Sizes\\n');\n }\n\n console.log(` Base: ${base}`);\n console.log(' Comparing to: working tree (includes uncommitted changes)');\n console.log(` Max lines for modified files: ${maxLines}`);\n if (forceLimit) {\n console.log(' Force limit: ENABLED (disable comments will be ignored)');\n }\n console.log('');\n\n try {\n const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base);\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 const violations = findViolations(workspaceRoot, changedFiles, maxLines, forceLimit);\n\n if (violations.length === 0) {\n console.log('✅ All modified files are under ' + maxLines + ' lines');\n return { success: true };\n }\n\n writeTmpInstructions(workspaceRoot);\n reportViolations(violations, maxLines, forceLimit);\n return { success: false };\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('❌ Modified files validation failed:', error.message);\n return { success: false };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-modified-files/executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AA0cH,8BA+DC;;AAtgBD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAoB7B,MAAM,OAAO,GAAG,eAAe,CAAC;AAChC,MAAM,WAAW,GA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YAAY,CAAC,MAAM,qBAAqB,CAAC,CAAC;QAErE,MAAM,UAAU,GAAG,cAAc,CAAC,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAE/E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,iCAAiC,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;YACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACpC,gBAAgB,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC7C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACpE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;AACL,CAAC","sourcesContent":["/**\n * Validate Modified Files Executor\n *\n * Validates that modified files don't exceed a maximum line count (default 900).\n * This encourages keeping files small and focused - when you touch a file,\n * you must bring it under the limit.\n *\n * Usage:\n * nx affected --target=validate-modified-files --base=origin/main\n *\n * Escape hatch: Add webpieces-disable max-lines-modified-files comment with date and justification\n * Format: // webpieces-disable max-lines-modified-files 2025/01/15 -- [reason]\n * The disable expires after 1 month from the date specified.\n */\n\nimport type { ExecutorContext } from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';\n\nexport interface ValidateModifiedFilesOptions {\n max?: number;\n mode?: ValidationMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface FileViolation {\n file: string;\n lines: number;\n expiredDisable?: boolean;\n expiredDate?: string;\n}\n\nconst TMP_DIR = 'tmp/webpieces';\nconst TMP_MD_FILE = 'webpieces.filesize.md';\n\nconst FILESIZE_DOC_CONTENT = `# AI Agent Instructions: File Too Long\n\n**READ THIS FILE to fix files that are too long**\n\n## Core Principle\n\nWith **stateless systems + dependency injection, refactor is trivial**.\nPick a method or a few and move to new class XXXXX, then inject XXXXX\ninto all users of those methods via the constructor.\nDelete those methods from original class.\n\n**99% of files can be less than the configured max lines of code.**\n\nFiles should contain a SINGLE COHESIVE UNIT.\n- One class per file (Java convention)\n- If class is too large, extract child responsibilities\n- Use dependency injection to compose functionality\n\n## Command: Reduce File Size\n\n### Step 1: Check for Multiple Classes\nIf the file contains multiple classes, **SEPARATE each class into its own file**.\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (multiple classes)\nexport class UserController { /* ... */ }\nexport class UserValidator { /* ... */ }\nexport class UserNotifier { /* ... */ }\n\n// GOOD: Three separate files\n// UserController.ts\nexport class UserController { /* ... */ }\n\n// UserValidator.ts\nexport class UserValidator { /* ... */ }\n\n// UserNotifier.ts\nexport class UserNotifier { /* ... */ }\n\\`\\`\\`\n\n### Step 2: Extract Child Responsibilities (if single class is too large)\n\n#### Pattern: Create New Service Class with Dependency Injection\n\n\\`\\`\\`typescript\n// BAD: UserController.ts (800 lines, single class)\n@provideSingleton()\n@Controller()\nexport class UserController {\n // 200 lines: CRUD operations\n // 300 lines: validation logic\n // 200 lines: notification logic\n // 100 lines: analytics logic\n}\n\n// GOOD: Extract validation service\n// 1. Create UserValidationService.ts\n@provideSingleton()\nexport class UserValidationService {\n validateUserData(data: UserData): ValidationResult {\n // 300 lines of validation logic moved here\n }\n\n validateEmail(email: string): boolean { /* ... */ }\n validatePassword(password: string): boolean { /* ... */ }\n}\n\n// 2. Inject into UserController.ts\n@provideSingleton()\n@Controller()\nexport class UserController {\n constructor(\n @inject(TYPES.UserValidationService)\n private validator: UserValidationService\n ) {}\n\n async createUser(data: UserData): Promise<User> {\n const validation = this.validator.validateUserData(data);\n if (!validation.isValid) {\n throw new ValidationError(validation.errors);\n }\n // ... rest of logic\n }\n}\n\\`\\`\\`\n\n## AI Agent Action Steps\n\n1. **ANALYZE** the file structure:\n - Count classes (if >1, separate immediately)\n - Identify logical responsibilities within single class\n\n2. **IDENTIFY** \"child code\" to extract:\n - Validation logic -> ValidationService\n - Notification logic -> NotificationService\n - Data transformation -> TransformerService\n - External API calls -> ApiService\n - Business rules -> RulesEngine\n\n3. **CREATE** new service file(s):\n - Start with temporary name: \\`XXXX.ts\\` or \\`ChildService.ts\\`\n - Add \\`@provideSingleton()\\` decorator\n - Move child methods to new class\n\n4. **UPDATE** dependency injection:\n - Add to \\`TYPES\\` constants (if using symbol-based DI)\n - Inject new service into original class constructor\n - Replace direct method calls with \\`this.serviceName.method()\\`\n\n5. **RENAME** extracted file:\n - Read the extracted code to understand its purpose\n - Rename \\`XXXX.ts\\` to logical name (e.g., \\`UserValidationService.ts\\`)\n\n6. **VERIFY** file sizes:\n - Original file should now be under the limit\n - Each extracted file should be under the limit\n - If still too large, extract more services\n\n## Examples of Child Responsibilities to Extract\n\n| If File Contains | Extract To | Pattern |\n|-----------------|------------|---------|\n| Validation logic (200+ lines) | \\`XValidator.ts\\` or \\`XValidationService.ts\\` | Singleton service |\n| Notification logic (150+ lines) | \\`XNotifier.ts\\` or \\`XNotificationService.ts\\` | Singleton service |\n| Data transformation (200+ lines) | \\`XTransformer.ts\\` | Singleton service |\n| External API calls (200+ lines) | \\`XApiClient.ts\\` | Singleton service |\n| Complex business rules (300+ lines) | \\`XRulesEngine.ts\\` | Singleton service |\n| Database queries (200+ lines) | \\`XRepository.ts\\` | Singleton service |\n\n## WebPieces Dependency Injection Pattern\n\n\\`\\`\\`typescript\n// 1. Define service with @provideSingleton\nimport { provideSingleton } from '@webpieces/http-routing';\n\n@provideSingleton()\nexport class MyService {\n doSomething(): void { /* ... */ }\n}\n\n// 2. Inject into consumer\nimport { inject } from 'inversify';\nimport { TYPES } from './types';\n\n@provideSingleton()\n@Controller()\nexport class MyController {\n constructor(\n @inject(TYPES.MyService) private service: MyService\n ) {}\n}\n\\`\\`\\`\n\n## Escape Hatch\n\nIf refactoring is genuinely not feasible (generated files, complex algorithms, etc.),\nadd a disable comment at the TOP of the file (within first 5 lines) with a DATE:\n\n\\`\\`\\`typescript\n// webpieces-disable max-lines-modified-files 2025/01/15 -- Complex generated file, refactoring would break generation\n\\`\\`\\`\n\n**IMPORTANT**: The date format is yyyy/mm/dd. The disable will EXPIRE after 1 month from this date.\nAfter expiration, you must either fix the file or update the date to get another month.\nThis ensures that disable comments are reviewed periodically.\n\nRemember: Find the \"child code\" and pull it down into a new class. Once moved, the code's purpose becomes clear, making it easy to rename to a logical name.\n`;\n\n/**\n * Write the instructions documentation to tmp directory\n */\nfunction writeTmpInstructions(workspaceRoot: string): string {\n const tmpDir = path.join(workspaceRoot, TMP_DIR);\n const mdPath = path.join(tmpDir, TMP_MD_FILE);\n\n fs.mkdirSync(tmpDir, { recursive: true });\n fs.writeFileSync(mdPath, FILESIZE_DOC_CONTENT);\n\n return mdPath;\n}\n\n/**\n * Get changed TypeScript files between base and working tree.\n * Uses `git diff base` (no three-dots) to match what `nx affected` does -\n * this includes both committed and uncommitted changes in one diff.\n */\nfunction getChangedTypeScriptFiles(workspaceRoot: string, base: string): string[] {\n try {\n // Use two-dot diff (base to working tree) - same as nx affected\n const output = execSync(`git diff --name-only ${base} -- '*.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 * Parse a date string in yyyy/mm/dd format and return a Date object.\n * Returns null if the format is invalid.\n */\nfunction parseDisableDate(dateStr: string): Date | null {\n // Match yyyy/mm/dd format\n const match = dateStr.match(/^(\\d{4})\\/(\\d{2})\\/(\\d{2})$/);\n if (!match) return null;\n\n const year = parseInt(match[1], 10);\n const month = parseInt(match[2], 10) - 1; // JS months are 0-indexed\n const day = parseInt(match[3], 10);\n\n const date = new Date(year, month, day);\n\n // Validate the date is valid (e.g., not Feb 30)\n if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) {\n return null;\n }\n\n return date;\n}\n\n/**\n * Check if a date is within the last month (not expired).\n */\nfunction isDateWithinMonth(date: Date): boolean {\n const now = new Date();\n const oneMonthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());\n return date >= oneMonthAgo;\n}\n\ninterface DisableStatus {\n hasDisable: boolean;\n isValid: boolean;\n isExpired: boolean;\n date?: string;\n}\n\n/**\n * Check if a file has a valid, non-expired disable comment at the top (within first 5 lines).\n * Returns status object with details about the disable comment.\n */\n// webpieces-disable max-lines-new-methods -- Date validation logic requires checking multiple conditions\nfunction checkDisableComment(content: string): DisableStatus {\n const lines = content.split('\\n').slice(0, 5);\n\n for (const line of lines) {\n if (line.includes('webpieces-disable') && line.includes('max-lines-modified-files')) {\n // Found disable comment, now check for date\n // Format: // webpieces-disable max-lines-modified-files yyyy/mm/dd -- reason\n const dateMatch = line.match(/max-lines-modified-files\\s+(\\d{4}\\/\\d{2}\\/\\d{2}|XXXX\\/XX\\/XX)/);\n\n if (!dateMatch) {\n // No date found - invalid disable comment\n return { hasDisable: true, isValid: false, isExpired: false };\n }\n\n const dateStr = dateMatch[1];\n\n // Secret permanent disable\n if (dateStr === 'XXXX/XX/XX') {\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n\n const date = parseDisableDate(dateStr);\n if (!date) {\n // Invalid date format\n return { hasDisable: true, isValid: false, isExpired: false, date: dateStr };\n }\n\n if (!isDateWithinMonth(date)) {\n // Date is expired (older than 1 month)\n return { hasDisable: true, isValid: true, isExpired: true, date: dateStr };\n }\n\n // Valid and not expired\n return { hasDisable: true, isValid: true, isExpired: false, date: dateStr };\n }\n }\n\n return { hasDisable: false, isValid: false, isExpired: false };\n}\n\n/**\n * Count lines in a file and check for violations\n */\n// webpieces-disable max-lines-new-methods -- File iteration with disable checking logic\nfunction findViolations(workspaceRoot: string, changedFiles: string[], maxLines: number, mode: ValidationMode): FileViolation[] {\n const violations: FileViolation[] = [];\n\n for (const file of changedFiles) {\n const fullPath = path.join(workspaceRoot, file);\n\n if (!fs.existsSync(fullPath)) continue;\n\n const content = fs.readFileSync(fullPath, 'utf-8');\n const lineCount = content.split('\\n').length;\n\n // Skip files under the limit\n if (lineCount <= maxLines) continue;\n\n // When mode is STRICT, ignore all disable comments\n if (mode === 'STRICT') {\n violations.push({ file, lines: lineCount });\n continue;\n }\n\n // Check for disable comment\n const disableStatus = checkDisableComment(content);\n\n if (disableStatus.hasDisable) {\n if (disableStatus.isValid && !disableStatus.isExpired) {\n // Valid, non-expired disable - skip this file\n continue;\n }\n\n if (disableStatus.isExpired) {\n // Expired disable - report as violation with expired info\n violations.push({\n file,\n lines: lineCount,\n expiredDisable: true,\n expiredDate: disableStatus.date,\n });\n continue;\n }\n\n // Invalid disable (missing/bad date) - fall through to report as violation\n }\n\n violations.push({\n file,\n lines: lineCount,\n });\n }\n\n return violations;\n}\n\n/**\n * Auto-detect the base branch by finding the merge-base with origin/main.\n */\nfunction detectBase(workspaceRoot: string): string | null {\n try {\n const mergeBase = execSync('git merge-base HEAD origin/main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n try {\n const mergeBase = execSync('git merge-base HEAD main', {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n if (mergeBase) {\n return mergeBase;\n }\n } catch {\n // Ignore\n }\n }\n return null;\n}\n\n/**\n * Get today's date in yyyy/mm/dd format for error messages\n */\nfunction getTodayDateString(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}/${month}/${day}`;\n}\n\n/**\n * Report violations to console\n */\n// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections\nfunction reportViolations(violations: FileViolation[], maxLines: number, mode: ValidationMode): void {\n console.error('');\n console.error('❌ YOU MUST FIX THIS AND NOT be more than ' + maxLines + ' lines of code per file');\n console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');\n console.error('');\n console.error('📚 With stateless systems + dependency injection, refactor is trivial:');\n console.error(' Pick a method or a few and move to new class XXXXX, then inject XXXXX');\n console.error(' into all users of those methods via the constructor.');\n console.error(' Delete those methods from original class.');\n console.error(' 99% of files can be less than ' + maxLines + ' lines of code.');\n console.error('');\n console.error('⚠️ *** READ tmp/webpieces/webpieces.filesize.md for detailed guidance on how to fix this easily *** ⚠️');\n console.error('');\n\n for (const v of violations) {\n if (v.expiredDisable) {\n console.error(` ❌ ${v.file} (${v.lines} lines, max: ${maxLines})`);\n console.error(` ⏰ EXPIRED DISABLE: Your disable comment dated ${v.expiredDate} has expired (>1 month old).`);\n console.error(` You must either FIX the file or UPDATE the date to get another month.`);\n } else {\n console.error(` ❌ ${v.file} (${v.lines} lines, max: ${maxLines})`);\n }\n }\n console.error('');\n\n // Only show escape hatch instructions when mode is not STRICT\n if (mode !== 'STRICT') {\n console.error(' You can disable this error, but you will be forced to fix again in 1 month');\n console.error(' since 99% of files can be less than ' + maxLines + ' lines of code.');\n console.error('');\n console.error(' Use escape with DATE (expires in 1 month):');\n console.error(` // webpieces-disable max-lines-modified-files ${getTodayDateString()} -- [your reason]`);\n console.error('');\n } else {\n console.error(' ⚠️ validationMode is STRICT - disable comments are NOT allowed.');\n console.error(' You MUST refactor to reduce file size.');\n console.error('');\n }\n}\n\nexport default async function runExecutor(\n options: ValidateModifiedFilesOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const workspaceRoot = context.root;\n const maxLines = options.max ?? 900;\n const mode: ValidationMode = options.mode ?? 'NORMAL';\n\n // Skip validation entirely if mode is OFF\n if (mode === 'OFF') {\n console.log('\\n⏭️ Skipping modified files validation (validationMode: OFF)');\n console.log('');\n return { success: true };\n }\n\n let base = process.env['NX_BASE'];\n\n if (!base) {\n base = detectBase(workspaceRoot) ?? undefined;\n\n if (!base) {\n console.log('\\n⏭️ Skipping modified files validation (could not detect base branch)');\n console.log(' To run explicitly: nx affected --target=validate-modified-files --base=origin/main');\n console.log('');\n return { success: true };\n }\n\n console.log('\\n📏 Validating Modified File Sizes (auto-detected base)\\n');\n } else {\n console.log('\\n📏 Validating Modified File Sizes\\n');\n }\n\n console.log(` Base: ${base}`);\n console.log(' Comparing to: working tree (includes uncommitted changes)');\n console.log(` Max lines for modified files: ${maxLines}`);\n console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored)' : ''}`);\n console.log('');\n\n try {\n const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base);\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 const violations = findViolations(workspaceRoot, changedFiles, maxLines, mode);\n\n if (violations.length === 0) {\n console.log('✅ All modified files are under ' + maxLines + ' lines');\n return { success: true };\n }\n\n writeTmpInstructions(workspaceRoot);\n reportViolations(violations, maxLines, mode);\n return { success: false };\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error(String(err));\n console.error('❌ Modified files validation failed:', error.message);\n return { success: false };\n }\n}\n"]}
|
|
@@ -18,9 +18,11 @@ import { execSync } from 'child_process';
|
|
|
18
18
|
import * as fs from 'fs';
|
|
19
19
|
import * as path from 'path';
|
|
20
20
|
|
|
21
|
+
export type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';
|
|
22
|
+
|
|
21
23
|
export interface ValidateModifiedFilesOptions {
|
|
22
24
|
max?: number;
|
|
23
|
-
|
|
25
|
+
mode?: ValidationMode;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface ExecutorResult {
|
|
@@ -328,7 +330,7 @@ function checkDisableComment(content: string): DisableStatus {
|
|
|
328
330
|
* Count lines in a file and check for violations
|
|
329
331
|
*/
|
|
330
332
|
// webpieces-disable max-lines-new-methods -- File iteration with disable checking logic
|
|
331
|
-
function findViolations(workspaceRoot: string, changedFiles: string[], maxLines: number,
|
|
333
|
+
function findViolations(workspaceRoot: string, changedFiles: string[], maxLines: number, mode: ValidationMode): FileViolation[] {
|
|
332
334
|
const violations: FileViolation[] = [];
|
|
333
335
|
|
|
334
336
|
for (const file of changedFiles) {
|
|
@@ -342,8 +344,8 @@ function findViolations(workspaceRoot: string, changedFiles: string[], maxLines:
|
|
|
342
344
|
// Skip files under the limit
|
|
343
345
|
if (lineCount <= maxLines) continue;
|
|
344
346
|
|
|
345
|
-
// When
|
|
346
|
-
if (
|
|
347
|
+
// When mode is STRICT, ignore all disable comments
|
|
348
|
+
if (mode === 'STRICT') {
|
|
347
349
|
violations.push({ file, lines: lineCount });
|
|
348
350
|
continue;
|
|
349
351
|
}
|
|
@@ -427,7 +429,7 @@ function getTodayDateString(): string {
|
|
|
427
429
|
* Report violations to console
|
|
428
430
|
*/
|
|
429
431
|
// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections
|
|
430
|
-
function reportViolations(violations: FileViolation[], maxLines: number,
|
|
432
|
+
function reportViolations(violations: FileViolation[], maxLines: number, mode: ValidationMode): void {
|
|
431
433
|
console.error('');
|
|
432
434
|
console.error('❌ YOU MUST FIX THIS AND NOT be more than ' + maxLines + ' lines of code per file');
|
|
433
435
|
console.error(' as it slows down IDEs AND is VERY VERY EASY to refactor.');
|
|
@@ -452,8 +454,8 @@ function reportViolations(violations: FileViolation[], maxLines: number, forceLi
|
|
|
452
454
|
}
|
|
453
455
|
console.error('');
|
|
454
456
|
|
|
455
|
-
// Only show escape hatch instructions when
|
|
456
|
-
if (
|
|
457
|
+
// Only show escape hatch instructions when mode is not STRICT
|
|
458
|
+
if (mode !== 'STRICT') {
|
|
457
459
|
console.error(' You can disable this error, but you will be forced to fix again in 1 month');
|
|
458
460
|
console.error(' since 99% of files can be less than ' + maxLines + ' lines of code.');
|
|
459
461
|
console.error('');
|
|
@@ -461,7 +463,7 @@ function reportViolations(violations: FileViolation[], maxLines: number, forceLi
|
|
|
461
463
|
console.error(` // webpieces-disable max-lines-modified-files ${getTodayDateString()} -- [your reason]`);
|
|
462
464
|
console.error('');
|
|
463
465
|
} else {
|
|
464
|
-
console.error(' ⚠️
|
|
466
|
+
console.error(' ⚠️ validationMode is STRICT - disable comments are NOT allowed.');
|
|
465
467
|
console.error(' You MUST refactor to reduce file size.');
|
|
466
468
|
console.error('');
|
|
467
469
|
}
|
|
@@ -473,7 +475,14 @@ export default async function runExecutor(
|
|
|
473
475
|
): Promise<ExecutorResult> {
|
|
474
476
|
const workspaceRoot = context.root;
|
|
475
477
|
const maxLines = options.max ?? 900;
|
|
476
|
-
const
|
|
478
|
+
const mode: ValidationMode = options.mode ?? 'NORMAL';
|
|
479
|
+
|
|
480
|
+
// Skip validation entirely if mode is OFF
|
|
481
|
+
if (mode === 'OFF') {
|
|
482
|
+
console.log('\n⏭️ Skipping modified files validation (validationMode: OFF)');
|
|
483
|
+
console.log('');
|
|
484
|
+
return { success: true };
|
|
485
|
+
}
|
|
477
486
|
|
|
478
487
|
let base = process.env['NX_BASE'];
|
|
479
488
|
|
|
@@ -495,9 +504,7 @@ export default async function runExecutor(
|
|
|
495
504
|
console.log(` Base: ${base}`);
|
|
496
505
|
console.log(' Comparing to: working tree (includes uncommitted changes)');
|
|
497
506
|
console.log(` Max lines for modified files: ${maxLines}`);
|
|
498
|
-
|
|
499
|
-
console.log(' Force limit: ENABLED (disable comments will be ignored)');
|
|
500
|
-
}
|
|
507
|
+
console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored)' : ''}`);
|
|
501
508
|
console.log('');
|
|
502
509
|
|
|
503
510
|
try {
|
|
@@ -510,7 +517,7 @@ export default async function runExecutor(
|
|
|
510
517
|
|
|
511
518
|
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
512
519
|
|
|
513
|
-
const violations = findViolations(workspaceRoot, changedFiles, maxLines,
|
|
520
|
+
const violations = findViolations(workspaceRoot, changedFiles, maxLines, mode);
|
|
514
521
|
|
|
515
522
|
if (violations.length === 0) {
|
|
516
523
|
console.log('✅ All modified files are under ' + maxLines + ' lines');
|
|
@@ -518,7 +525,7 @@ export default async function runExecutor(
|
|
|
518
525
|
}
|
|
519
526
|
|
|
520
527
|
writeTmpInstructions(workspaceRoot);
|
|
521
|
-
reportViolations(violations, maxLines,
|
|
528
|
+
reportViolations(violations, maxLines, mode);
|
|
522
529
|
return { success: false };
|
|
523
530
|
} catch (err: unknown) {
|
|
524
531
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"description": "Maximum number of lines allowed for modified files",
|
|
10
10
|
"default": 900
|
|
11
11
|
},
|
|
12
|
-
"
|
|
13
|
-
"type": "
|
|
14
|
-
"
|
|
15
|
-
"
|
|
12
|
+
"mode": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"enum": ["STRICT", "NORMAL", "OFF"],
|
|
15
|
+
"description": "STRICT: limits enforced, no disable comments. NORMAL: disable comments work. OFF: skip validation.",
|
|
16
|
+
"default": "NORMAL"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"required": []
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
* The disable expires after 1 month from the date specified.
|
|
20
20
|
*/
|
|
21
21
|
import type { ExecutorContext } from '@nx/devkit';
|
|
22
|
+
export type ValidationMode = 'STRICT' | 'NORMAL' | 'OFF';
|
|
22
23
|
export interface ValidateModifiedMethodsOptions {
|
|
23
24
|
max?: number;
|
|
25
|
+
mode?: ValidationMode;
|
|
24
26
|
}
|
|
25
27
|
export interface ExecutorResult {
|
|
26
28
|
success: boolean;
|
|
@@ -428,111 +428,80 @@ function findMethodsInFile(filePath, workspaceRoot) {
|
|
|
428
428
|
visit(sourceFile);
|
|
429
429
|
return methods;
|
|
430
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Check if a method has any changes within its line range
|
|
433
|
+
*/
|
|
434
|
+
function methodHasChanges(method, changedLineNumbers) {
|
|
435
|
+
for (let line = method.line; line <= method.endLine; line++) {
|
|
436
|
+
if (changedLineNumbers.has(line))
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Check a NEW method and return violation if applicable
|
|
443
|
+
*/
|
|
444
|
+
function checkNewMethodViolation(file, method, mode) {
|
|
445
|
+
const { type: disableType, isExpired, date: disableDate } = method.disableInfo;
|
|
446
|
+
if (mode === 'STRICT') {
|
|
447
|
+
// When mode is STRICT, skip NEW methods without escape (let validate-new-methods handle)
|
|
448
|
+
if (disableType === 'none')
|
|
449
|
+
return null;
|
|
450
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines };
|
|
451
|
+
}
|
|
452
|
+
if (disableType === 'full' && isExpired) {
|
|
453
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines, expiredDisable: true, expiredDate: disableDate };
|
|
454
|
+
}
|
|
455
|
+
if (disableType !== 'new-only')
|
|
456
|
+
return null;
|
|
457
|
+
if (isExpired) {
|
|
458
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines, expiredDisable: true, expiredDate: disableDate };
|
|
459
|
+
}
|
|
460
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines };
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Check a MODIFIED method and return violation if applicable
|
|
464
|
+
*/
|
|
465
|
+
function checkModifiedMethodViolation(file, method, mode) {
|
|
466
|
+
const { type: disableType, isExpired, date: disableDate } = method.disableInfo;
|
|
467
|
+
if (mode === 'STRICT') {
|
|
468
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines };
|
|
469
|
+
}
|
|
470
|
+
if (disableType === 'full' && isExpired) {
|
|
471
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines, expiredDisable: true, expiredDate: disableDate };
|
|
472
|
+
}
|
|
473
|
+
return { file, methodName: method.name, line: method.line, lines: method.lines };
|
|
474
|
+
}
|
|
431
475
|
/**
|
|
432
476
|
* Find methods that exceed the 80-line limit.
|
|
433
|
-
*
|
|
434
|
-
* This validator checks:
|
|
435
|
-
* 1. NEW methods that have `max-lines-new-methods` escape (they passed 30-line check, now need 80-line check)
|
|
436
|
-
* 2. MODIFIED methods (existing methods with changes)
|
|
437
|
-
*
|
|
438
|
-
* Skips:
|
|
439
|
-
* - NEW methods without any escape (let validate-new-methods handle them first)
|
|
440
|
-
* - Methods with valid, non-expired `max-lines-modified` escape (ultimate escape hatch)
|
|
477
|
+
* Checks NEW methods with escape hatches and MODIFIED methods.
|
|
441
478
|
*/
|
|
442
|
-
|
|
443
|
-
function findViolations(workspaceRoot, changedFiles, base, maxLines) {
|
|
479
|
+
function findViolations(workspaceRoot, changedFiles, base, maxLines, mode) {
|
|
444
480
|
const violations = [];
|
|
445
481
|
for (const file of changedFiles) {
|
|
446
482
|
const diff = getFileDiff(workspaceRoot, file, base);
|
|
447
483
|
if (!diff)
|
|
448
484
|
continue;
|
|
449
|
-
// Find NEW methods from the diff
|
|
450
485
|
const newMethodNames = findNewMethodSignaturesInDiff(diff);
|
|
451
|
-
// Find which lines have changes
|
|
452
486
|
const changedLineNumbers = getChangedLineNumbers(diff);
|
|
453
487
|
if (changedLineNumbers.size === 0)
|
|
454
488
|
continue;
|
|
455
|
-
// Parse the current file to get all methods
|
|
456
489
|
const methods = findMethodsInFile(file, workspaceRoot);
|
|
457
490
|
for (const method of methods) {
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (disableType === 'full' && !isExpired)
|
|
491
|
+
const { type: disableType, isExpired } = method.disableInfo;
|
|
492
|
+
// Skip methods with valid, non-expired full escape - unless mode is STRICT
|
|
493
|
+
if (mode !== 'STRICT' && disableType === 'full' && !isExpired)
|
|
462
494
|
continue;
|
|
463
|
-
// Skip methods under the limit
|
|
464
495
|
if (method.lines <= maxLines)
|
|
465
496
|
continue;
|
|
497
|
+
const isNewMethod = newMethodNames.has(method.name);
|
|
466
498
|
if (isNewMethod) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
// - If has expired disable → report as violation
|
|
471
|
-
if (disableType === 'full' && isExpired) {
|
|
472
|
-
// Expired full disable - report with expired info
|
|
473
|
-
violations.push({
|
|
474
|
-
file,
|
|
475
|
-
methodName: method.name,
|
|
476
|
-
line: method.line,
|
|
477
|
-
lines: method.lines,
|
|
478
|
-
expiredDisable: true,
|
|
479
|
-
expiredDate: disableDate,
|
|
480
|
-
});
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
483
|
-
if (disableType !== 'new-only')
|
|
484
|
-
continue;
|
|
485
|
-
if (isExpired) {
|
|
486
|
-
// Expired new-only disable - report with expired info
|
|
487
|
-
violations.push({
|
|
488
|
-
file,
|
|
489
|
-
methodName: method.name,
|
|
490
|
-
line: method.line,
|
|
491
|
-
lines: method.lines,
|
|
492
|
-
expiredDisable: true,
|
|
493
|
-
expiredDate: disableDate,
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
// New method with valid max-lines-new-methods escape - check against 80-line limit
|
|
498
|
-
violations.push({
|
|
499
|
-
file,
|
|
500
|
-
methodName: method.name,
|
|
501
|
-
line: method.line,
|
|
502
|
-
lines: method.lines,
|
|
503
|
-
});
|
|
504
|
-
}
|
|
499
|
+
const violation = checkNewMethodViolation(file, method, mode);
|
|
500
|
+
if (violation)
|
|
501
|
+
violations.push(violation);
|
|
505
502
|
}
|
|
506
|
-
else {
|
|
507
|
-
|
|
508
|
-
let hasChanges = false;
|
|
509
|
-
for (let line = method.line; line <= method.endLine; line++) {
|
|
510
|
-
if (changedLineNumbers.has(line)) {
|
|
511
|
-
hasChanges = true;
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
if (hasChanges) {
|
|
516
|
-
if (disableType === 'full' && isExpired) {
|
|
517
|
-
// Expired full disable - report with expired info
|
|
518
|
-
violations.push({
|
|
519
|
-
file,
|
|
520
|
-
methodName: method.name,
|
|
521
|
-
line: method.line,
|
|
522
|
-
lines: method.lines,
|
|
523
|
-
expiredDisable: true,
|
|
524
|
-
expiredDate: disableDate,
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
violations.push({
|
|
529
|
-
file,
|
|
530
|
-
methodName: method.name,
|
|
531
|
-
line: method.line,
|
|
532
|
-
lines: method.lines,
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
}
|
|
503
|
+
else if (methodHasChanges(method, changedLineNumbers)) {
|
|
504
|
+
violations.push(checkModifiedMethodViolation(file, method, mode));
|
|
536
505
|
}
|
|
537
506
|
}
|
|
538
507
|
}
|
|
@@ -573,7 +542,7 @@ function detectBase(workspaceRoot) {
|
|
|
573
542
|
* Report violations to console
|
|
574
543
|
*/
|
|
575
544
|
// webpieces-disable max-lines-new-methods -- Error output formatting with multiple message sections
|
|
576
|
-
function reportViolations(violations, maxLines) {
|
|
545
|
+
function reportViolations(violations, maxLines, mode) {
|
|
577
546
|
console.error('');
|
|
578
547
|
console.error('❌ Modified methods exceed ' + maxLines + ' lines!');
|
|
579
548
|
console.error('');
|
|
@@ -598,16 +567,31 @@ function reportViolations(violations, maxLines) {
|
|
|
598
567
|
}
|
|
599
568
|
}
|
|
600
569
|
console.error('');
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
570
|
+
// Only show escape hatch instructions when mode is not STRICT
|
|
571
|
+
if (mode !== 'STRICT') {
|
|
572
|
+
console.error(' You can disable this error, but you will be forced to fix again in 1 month');
|
|
573
|
+
console.error(' since 99% of methods can be less than ' + maxLines + ' lines of code.');
|
|
574
|
+
console.error('');
|
|
575
|
+
console.error(' Use escape with DATE (expires in 1 month):');
|
|
576
|
+
console.error(` // webpieces-disable max-lines-modified ${getTodayDateString()} -- [your reason]`);
|
|
577
|
+
console.error('');
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
console.error(' ⚠️ validationMode is STRICT - disable comments are NOT allowed.');
|
|
581
|
+
console.error(' You MUST refactor to reduce method size.');
|
|
582
|
+
console.error('');
|
|
583
|
+
}
|
|
607
584
|
}
|
|
608
585
|
async function runExecutor(options, context) {
|
|
609
586
|
const workspaceRoot = context.root;
|
|
610
587
|
const maxLines = options.max ?? 80;
|
|
588
|
+
const mode = options.mode ?? 'NORMAL';
|
|
589
|
+
// Skip validation entirely if mode is OFF
|
|
590
|
+
if (mode === 'OFF') {
|
|
591
|
+
console.log('\n⏭️ Skipping modified method validation (validationMode: OFF)');
|
|
592
|
+
console.log('');
|
|
593
|
+
return { success: true };
|
|
594
|
+
}
|
|
611
595
|
let base = process.env['NX_BASE'];
|
|
612
596
|
if (!base) {
|
|
613
597
|
base = detectBase(workspaceRoot) ?? undefined;
|
|
@@ -625,6 +609,7 @@ async function runExecutor(options, context) {
|
|
|
625
609
|
console.log(` Base: ${base}`);
|
|
626
610
|
console.log(' Comparing to: working tree (includes uncommitted changes)');
|
|
627
611
|
console.log(` Max lines for modified methods: ${maxLines}`);
|
|
612
|
+
console.log(` Validation mode: ${mode}${mode === 'STRICT' ? ' (disable comments ignored)' : ''}`);
|
|
628
613
|
console.log('');
|
|
629
614
|
try {
|
|
630
615
|
const changedFiles = getChangedTypeScriptFiles(workspaceRoot, base);
|
|
@@ -633,13 +618,13 @@ async function runExecutor(options, context) {
|
|
|
633
618
|
return { success: true };
|
|
634
619
|
}
|
|
635
620
|
console.log(`📂 Checking ${changedFiles.length} changed file(s)...`);
|
|
636
|
-
const violations = findViolations(workspaceRoot, changedFiles, base, maxLines);
|
|
621
|
+
const violations = findViolations(workspaceRoot, changedFiles, base, maxLines, mode);
|
|
637
622
|
if (violations.length === 0) {
|
|
638
623
|
console.log('✅ All modified methods are under ' + maxLines + ' lines');
|
|
639
624
|
return { success: true };
|
|
640
625
|
}
|
|
641
626
|
writeTmpInstructions(workspaceRoot);
|
|
642
|
-
reportViolations(violations, maxLines);
|
|
627
|
+
reportViolations(violations, maxLines, mode);
|
|
643
628
|
return { success: false };
|
|
644
629
|
}
|
|
645
630
|
catch (err) {
|