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

@@ -5,8 +5,12 @@ export type MediaUnderstandingScopeDecision = "allow" | "deny";
function normalizeDecision(value?: string | null): MediaUnderstandingScopeDecision | undefined {
const normalized = value?.trim().toLowerCase();
if (normalized === "allow") return "allow";
if (normalized === "deny") return "deny";
if (normalized === "allow") {
return "allow";
}
if (normalized === "deny") {
return "deny";
}
return undefined;
}
@@ -26,23 +30,33 @@ export function resolveMediaUnderstandingScope(params: {
chatType?: string;
}): MediaUnderstandingScopeDecision {
const scope = params.scope;
if (!scope) return "allow";
if (!scope) {
return "allow";
}
const channel = normalizeMatch(params.channel);
const chatType = normalizeMediaUnderstandingChatType(params.chatType);
const sessionKey = normalizeMatch(params.sessionKey) ?? "";
for (const rule of scope.rules ?? []) {
if (!rule) continue;
if (!rule) {
continue;
}
const action = normalizeDecision(rule.action) ?? "allow";
const match = rule.match ?? {};
const matchChannel = normalizeMatch(match.channel);
const matchChatType = normalizeMediaUnderstandingChatType(match.chatType);
const matchPrefix = normalizeMatch(match.keyPrefix);
if (matchChannel && matchChannel !== channel) continue;
if (matchChatType && matchChatType !== chatType) continue;
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) continue;
if (matchChannel && matchChannel !== channel) {
continue;
}
if (matchChatType && matchChatType !== chatType) {
continue;
}
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) {
continue;
}
return action;
}