chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -1,7 +1,9 @@
import type { ContextPruningToolMatch } from "./settings.js";
function normalizePatterns(patterns?: string[]): string[] {
if (!Array.isArray(patterns)) return [];
if (!Array.isArray(patterns)) {
return [];
}
return patterns
.map((p) =>
String(p ?? "")
@@ -17,8 +19,12 @@ type CompiledPattern =
| { kind: "regex"; value: RegExp };
function compilePattern(pattern: string): CompiledPattern {
if (pattern === "*") return { kind: "all" };
if (!pattern.includes("*")) return { kind: "exact", value: pattern };
if (pattern === "*") {
return { kind: "all" };
}
if (!pattern.includes("*")) {
return { kind: "exact", value: pattern };
}
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = new RegExp(`^${escaped.replaceAll("\\*", ".*")}$`);
@@ -31,9 +37,15 @@ function compilePatterns(patterns?: string[]): CompiledPattern[] {
function matchesAny(toolName: string, patterns: CompiledPattern[]): boolean {
for (const p of patterns) {
if (p.kind === "all") return true;
if (p.kind === "exact" && toolName === p.value) return true;
if (p.kind === "regex" && p.value.test(toolName)) return true;
if (p.kind === "all") {
return true;
}
if (p.kind === "exact" && toolName === p.value) {
return true;
}
if (p.kind === "regex" && p.value.test(toolName)) {
return true;
}
}
return false;
}
@@ -46,8 +58,12 @@ export function makeToolPrunablePredicate(
return (toolName: string) => {
const normalized = toolName.trim().toLowerCase();
if (matchesAny(normalized, deny)) return false;
if (allow.length === 0) return true;
if (matchesAny(normalized, deny)) {
return false;
}
if (allow.length === 0) {
return true;
}
return matchesAny(normalized, allow);
};
}