chore: relax loc check defaults

This commit is contained in:
الخاسر 2026-01-27 08:30:36 +05:30
parent dd1e161f5a
commit edf39d0a86
2 changed files with 24 additions and 4 deletions

View File

@ -140,7 +140,7 @@
"protocol:gen:swift": "node --import tsx scripts/protocol-gen-swift.ts", "protocol:gen:swift": "node --import tsx scripts/protocol-gen-swift.ts",
"protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/ClawdbotProtocol/GatewayModels.swift", "protocol:check": "pnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code -- dist/protocol.schema.json apps/macos/Sources/ClawdbotProtocol/GatewayModels.swift",
"canvas:a2ui:bundle": "bash scripts/bundle-a2ui.sh", "canvas:a2ui:bundle": "bash scripts/bundle-a2ui.sh",
"check:loc": "node --import tsx scripts/check-ts-max-loc.ts --max 500" "check:loc": "node --import tsx scripts/check-ts-max-loc.ts --max 3000"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",

View File

@ -4,10 +4,13 @@ import { execFileSync } from "node:child_process";
type ParsedArgs = { type ParsedArgs = {
maxLines: number; maxLines: number;
exclude: RegExp[];
}; };
function parseArgs(argv: string[]): ParsedArgs { function parseArgs(argv: string[]): ParsedArgs {
let maxLines = 500; let maxLines = 500;
const excludePatterns: string[] = [];
const defaultExcludePatterns = ["^(vendor|dist|docs|extensions|ui|apps)/"];
for (let index = 0; index < argv.length; index++) { for (let index = 0; index < argv.length; index++) {
const arg = argv[index]; const arg = argv[index];
@ -18,9 +21,25 @@ function parseArgs(argv: string[]): ParsedArgs {
index++; index++;
continue; continue;
} }
if (arg === "--exclude") {
const next = argv[index + 1];
if (!next) throw new Error("Missing --exclude value");
excludePatterns.push(next);
index++;
continue;
}
} }
return { maxLines }; const combinedPatterns = [...defaultExcludePatterns, ...excludePatterns];
const exclude = combinedPatterns.map((pattern) => {
try {
return new RegExp(pattern);
} catch {
throw new Error(`Invalid --exclude regex: ${pattern}`);
}
});
return { maxLines, exclude };
} }
function gitLsFilesAll(): string[] { function gitLsFilesAll(): string[] {
@ -47,10 +66,11 @@ async function main() {
throw error; throw error;
}); });
const { maxLines } = parseArgs(process.argv.slice(2)); const { maxLines, exclude } = parseArgs(process.argv.slice(2));
const files = gitLsFilesAll() const files = gitLsFilesAll()
.filter((filePath) => existsSync(filePath)) .filter((filePath) => existsSync(filePath))
.filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx")); .filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"))
.filter((filePath) => !exclude.some((pattern) => pattern.test(filePath)));
const results = await Promise.all( const results = await Promise.all(
files.map(async (filePath) => ({ filePath, lines: await countLines(filePath) })), files.map(async (filePath) => ({ filePath, lines: await countLines(filePath) })),