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

@@ -6,8 +6,12 @@ export type SessionSendPolicyDecision = "allow" | "deny";
export function normalizeSendPolicy(raw?: string | null): SessionSendPolicyDecision | undefined {
const value = raw?.trim().toLowerCase();
if (value === "allow") return "allow";
if (value === "deny") return "deny";
if (value === "allow") {
return "allow";
}
if (value === "deny") {
return "deny";
}
return undefined;
}
@@ -17,7 +21,9 @@ function normalizeMatchValue(raw?: string | null) {
}
function deriveChannelFromKey(key?: string) {
if (!key) return undefined;
if (!key) {
return undefined;
}
const parts = key.split(":").filter(Boolean);
if (parts.length >= 3 && (parts[1] === "group" || parts[1] === "channel")) {
return normalizeMatchValue(parts[0]);
@@ -26,9 +32,15 @@ function deriveChannelFromKey(key?: string) {
}
function deriveChatTypeFromKey(key?: string): SessionChatType | undefined {
if (!key) return undefined;
if (key.includes(":group:")) return "group";
if (key.includes(":channel:")) return "channel";
if (!key) {
return undefined;
}
if (key.includes(":group:")) {
return "group";
}
if (key.includes(":channel:")) {
return "channel";
}
return undefined;
}
@@ -40,10 +52,14 @@ export function resolveSendPolicy(params: {
chatType?: SessionChatType;
}): SessionSendPolicyDecision {
const override = normalizeSendPolicy(params.entry?.sendPolicy);
if (override) return override;
if (override) {
return override;
}
const policy = params.cfg.session?.sendPolicy;
if (!policy) return "allow";
if (!policy) {
return "allow";
}
const channel =
normalizeMatchValue(params.channel) ??
@@ -57,21 +73,33 @@ export function resolveSendPolicy(params: {
let allowedMatch = false;
for (const rule of policy.rules ?? []) {
if (!rule) continue;
if (!rule) {
continue;
}
const action = normalizeSendPolicy(rule.action) ?? "allow";
const match = rule.match ?? {};
const matchChannel = normalizeMatchValue(match.channel);
const matchChatType = normalizeChatType(match.chatType);
const matchPrefix = normalizeMatchValue(match.keyPrefix);
if (matchChannel && matchChannel !== channel) continue;
if (matchChatType && matchChatType !== chatType) continue;
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) continue;
if (action === "deny") return "deny";
if (matchChannel && matchChannel !== channel) {
continue;
}
if (matchChatType && matchChatType !== chatType) {
continue;
}
if (matchPrefix && !sessionKey.startsWith(matchPrefix)) {
continue;
}
if (action === "deny") {
return "deny";
}
allowedMatch = true;
}
if (allowedMatch) return "allow";
if (allowedMatch) {
return "allow";
}
const fallback = normalizeSendPolicy(policy.default);
return fallback ?? "allow";