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

@@ -46,7 +46,9 @@ function normalizeMode(value?: string): RedactSensitiveMode {
}
function parsePattern(raw: string): RegExp | null {
if (!raw.trim()) return null;
if (!raw.trim()) {
return null;
}
const match = raw.match(/^\/(.+)\/([gimsuy]*)$/);
try {
if (match) {
@@ -65,7 +67,9 @@ function resolvePatterns(value?: string[]): RegExp[] {
}
function maskToken(token: string): string {
if (token.length < DEFAULT_REDACT_MIN_LENGTH) return "***";
if (token.length < DEFAULT_REDACT_MIN_LENGTH) {
return "***";
}
const start = token.slice(0, DEFAULT_REDACT_KEEP_START);
const end = token.slice(-DEFAULT_REDACT_KEEP_END);
return `${start}${end}`;
@@ -73,16 +77,22 @@ function maskToken(token: string): string {
function redactPemBlock(block: string): string {
const lines = block.split(/\r?\n/).filter(Boolean);
if (lines.length < 2) return "***";
if (lines.length < 2) {
return "***";
}
return `${lines[0]}\n…redacted…\n${lines[lines.length - 1]}`;
}
function redactMatch(match: string, groups: string[]): string {
if (match.includes("PRIVATE KEY-----")) return redactPemBlock(match);
if (match.includes("PRIVATE KEY-----")) {
return redactPemBlock(match);
}
const token =
groups.filter((value) => typeof value === "string" && value.length > 0).at(-1) ?? match;
const masked = maskToken(token);
if (token === match) return masked;
if (token === match) {
return masked;
}
return match.replace(token, masked);
}
@@ -113,17 +123,25 @@ function resolveConfigRedaction(): RedactOptions {
}
export function redactSensitiveText(text: string, options?: RedactOptions): string {
if (!text) return text;
if (!text) {
return text;
}
const resolved = options ?? resolveConfigRedaction();
if (normalizeMode(resolved.mode) === "off") return text;
if (normalizeMode(resolved.mode) === "off") {
return text;
}
const patterns = resolvePatterns(resolved.patterns);
if (!patterns.length) return text;
if (!patterns.length) {
return text;
}
return redactText(text, patterns);
}
export function redactToolDetail(detail: string): string {
const resolved = resolveConfigRedaction();
if (normalizeMode(resolved.mode) !== "tools") return detail;
if (normalizeMode(resolved.mode) !== "tools") {
return detail;
}
return redactSensitiveText(detail, resolved);
}