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

@@ -12,16 +12,26 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move bindings[].match.provider to bindings[].match.channel",
apply: (raw, changes) => {
const bindings = Array.isArray(raw.bindings) ? raw.bindings : null;
if (!bindings) return;
if (!bindings) {
return;
}
let touched = false;
for (const entry of bindings) {
if (!isRecord(entry)) continue;
if (!isRecord(entry)) {
continue;
}
const match = getRecord(entry.match);
if (!match) continue;
if (typeof match.channel === "string" && match.channel.trim()) continue;
if (!match) {
continue;
}
if (typeof match.channel === "string" && match.channel.trim()) {
continue;
}
const provider = typeof match.provider === "string" ? match.provider.trim() : "";
if (!provider) continue;
if (!provider) {
continue;
}
match.channel = provider;
delete match.provider;
entry.match = match;
@@ -39,17 +49,27 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move bindings[].match.accountID to bindings[].match.accountId",
apply: (raw, changes) => {
const bindings = Array.isArray(raw.bindings) ? raw.bindings : null;
if (!bindings) return;
if (!bindings) {
return;
}
let touched = false;
for (const entry of bindings) {
if (!isRecord(entry)) continue;
if (!isRecord(entry)) {
continue;
}
const match = getRecord(entry.match);
if (!match) continue;
if (match.accountId !== undefined) continue;
if (!match) {
continue;
}
if (match.accountId !== undefined) {
continue;
}
const accountID =
typeof match.accountID === "string" ? match.accountID.trim() : match.accountID;
if (!accountID) continue;
if (!accountID) {
continue;
}
match.accountId = accountID;
delete match.accountID;
entry.match = match;
@@ -67,20 +87,34 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move session.sendPolicy.rules[].match.provider to match.channel",
apply: (raw, changes) => {
const session = getRecord(raw.session);
if (!session) return;
if (!session) {
return;
}
const sendPolicy = getRecord(session.sendPolicy);
if (!sendPolicy) return;
if (!sendPolicy) {
return;
}
const rules = Array.isArray(sendPolicy.rules) ? sendPolicy.rules : null;
if (!rules) return;
if (!rules) {
return;
}
let touched = false;
for (const rule of rules) {
if (!isRecord(rule)) continue;
if (!isRecord(rule)) {
continue;
}
const match = getRecord(rule.match);
if (!match) continue;
if (typeof match.channel === "string" && match.channel.trim()) continue;
if (!match) {
continue;
}
if (typeof match.channel === "string" && match.channel.trim()) {
continue;
}
const provider = typeof match.provider === "string" ? match.provider.trim() : "";
if (!provider) continue;
if (!provider) {
continue;
}
match.channel = provider;
delete match.provider;
rule.match = match;
@@ -100,10 +134,16 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move messages.queue.byProvider to messages.queue.byChannel",
apply: (raw, changes) => {
const messages = getRecord(raw.messages);
if (!messages) return;
if (!messages) {
return;
}
const queue = getRecord(messages.queue);
if (!queue) return;
if (queue.byProvider === undefined) return;
if (!queue) {
return;
}
if (queue.byProvider === undefined) {
return;
}
if (queue.byChannel === undefined) {
queue.byChannel = queue.byProvider;
changes.push("Moved messages.queue.byProvider → messages.queue.byChannel.");
@@ -129,12 +169,16 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
"msteams",
];
const legacyEntries = legacyKeys.filter((key) => isRecord(raw[key]));
if (legacyEntries.length === 0) return;
if (legacyEntries.length === 0) {
return;
}
const channels = ensureRecord(raw, "channels");
for (const key of legacyEntries) {
const legacy = getRecord(raw[key]);
if (!legacy) continue;
if (!legacy) {
continue;
}
const channelEntry = ensureRecord(channels, key);
const hadEntries = Object.keys(channelEntry).length > 0;
mergeMissing(channelEntry, legacy);
@@ -152,9 +196,13 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move routing.allowFrom to channels.whatsapp.allowFrom",
apply: (raw, changes) => {
const routing = raw.routing;
if (!routing || typeof routing !== "object") return;
if (!routing || typeof routing !== "object") {
return;
}
const allowFrom = (routing as Record<string, unknown>).allowFrom;
if (allowFrom === undefined) return;
if (allowFrom === undefined) {
return;
}
const channels = getRecord(raw.channels);
const whatsapp = channels ? getRecord(channels.whatsapp) : null;
@@ -187,22 +235,30 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move routing.groupChat.requireMention to channels.whatsapp/telegram/imessage groups",
apply: (raw, changes) => {
const routing = raw.routing;
if (!routing || typeof routing !== "object") return;
if (!routing || typeof routing !== "object") {
return;
}
const groupChat =
(routing as Record<string, unknown>).groupChat &&
typeof (routing as Record<string, unknown>).groupChat === "object"
? ((routing as Record<string, unknown>).groupChat as Record<string, unknown>)
: null;
if (!groupChat) return;
if (!groupChat) {
return;
}
const requireMention = groupChat.requireMention;
if (requireMention === undefined) return;
if (requireMention === undefined) {
return;
}
const channels = ensureRecord(raw, "channels");
const applyTo = (
key: "whatsapp" | "telegram" | "imessage",
options?: { requireExisting?: boolean },
) => {
if (options?.requireExisting && !isRecord(channels[key])) return;
if (options?.requireExisting && !isRecord(channels[key])) {
return;
}
const section =
channels[key] && typeof channels[key] === "object"
? (channels[key] as Record<string, unknown>)
@@ -250,9 +306,13 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
describe: "Move gateway.token to gateway.auth.token",
apply: (raw, changes) => {
const gateway = raw.gateway;
if (!gateway || typeof gateway !== "object") return;
if (!gateway || typeof gateway !== "object") {
return;
}
const token = (gateway as Record<string, unknown>).token;
if (token === undefined) return;
if (token === undefined) {
return;
}
const gatewayObj = gateway as Record<string, unknown>;
const auth =
@@ -261,7 +321,9 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
: {};
if (auth.token === undefined) {
auth.token = token;
if (!auth.mode) auth.mode = "token";
if (!auth.mode) {
auth.mode = "token";
}
changes.push("Moved gateway.token → gateway.auth.token.");
} else {
changes.push("Removed gateway.token (gateway.auth.token already set).");
@@ -279,9 +341,13 @@ export const LEGACY_CONFIG_MIGRATIONS_PART_1: LegacyConfigMigration[] = [
apply: (raw, changes) => {
const channels = ensureRecord(raw, "channels");
const telegram = channels.telegram;
if (!telegram || typeof telegram !== "object") return;
if (!telegram || typeof telegram !== "object") {
return;
}
const requireMention = (telegram as Record<string, unknown>).requireMention;
if (requireMention === undefined) return;
if (requireMention === undefined) {
return;
}
const groups =
(telegram as Record<string, unknown>).groups &&