#!/usr/bin/env node /** * Regenerates tools/eslint/max-lines-baseline.mjs: the list of TypeScript * files that already exceed the max-lines limit enforced in eslint.config.mjs. * Baselined files are exempt from the rule; the list should only shrink. * * Usage: node tools/eslint/generate-max-lines-baseline.mjs */ import { readdirSync, readFileSync, writeFileSync } from 'node:fs'; import path from 'node:path'; import process from 'node:process'; export const MAX_LINES = 400; const workspaceRoot = process.cwd(); const scanRoots = ['apps', 'libs', 'tools']; const skipDirs = new Set(['node_modules', 'dist', '.nx', 'coverage']); function collectTsFiles(dir, results) { for (const entry of readdirSync(dir, { withFileTypes: true })) { if (entry.isDirectory()) { if (!skipDirs.has(entry.name)) { collectTsFiles(path.join(dir, entry.name), results); } } else if ( (entry.name.endsWith('.ts') || entry.name.endsWith('.tsx')) && !entry.name.endsWith('.d.ts') ) { results.push(path.join(dir, entry.name)); } } return results; } function countLines(filePath) { const content = readFileSync(filePath, 'utf8'); if (content.length === 0) { return 0; } const lines = content.split('\n').length; return content.endsWith('\n') ? lines - 1 : lines; } const offenders = scanRoots .flatMap((root) => collectTsFiles(path.join(workspaceRoot, root), [])) .map((filePath) => ({ file: path.relative(workspaceRoot, filePath).split(path.sep).join('/'), lines: countLines(filePath), })) .filter(({ lines }) => lines > MAX_LINES) .sort((a, b) => a.file.localeCompare(b.file)); const banner = `// Generated by tools/eslint/generate-max-lines-baseline.mjs — do not edit by hand. // TypeScript files that predate the max-lines (${MAX_LINES}) ESLint rule. // This list should only shrink: split a file below the limit, rerun the // generator, and commit the result. Never add new files here. `; const body = offenders.map(({ file }) => ` '${file}',`).join('\n'); writeFileSync( path.join(workspaceRoot, 'tools/eslint/max-lines-baseline.mjs'), `${banner}export const maxLinesBaseline = [\n${body}\n];\n` ); console.log(`Baselined ${offenders.length} files over ${MAX_LINES} lines.`);