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

@@ -35,11 +35,17 @@ function parseDiscordChannelInput(raw: string): {
guildOnly?: boolean;
} {
const trimmed = raw.trim();
if (!trimmed) return {};
if (!trimmed) {
return {};
}
const mention = trimmed.match(/^<#(\d+)>$/);
if (mention) return { channelId: mention[1] };
if (mention) {
return { channelId: mention[1] };
}
const channelPrefix = trimmed.match(/^(?:channel:|discord:)?(\d+)$/i);
if (channelPrefix) return { channelId: channelPrefix[1] };
if (channelPrefix) {
return { channelId: channelPrefix[1] };
}
const guildPrefix = trimmed.match(/^(?:guild:|server:)?(\d+)$/i);
if (guildPrefix && !trimmed.includes("/") && !trimmed.includes("#")) {
return { guildId: guildPrefix[1], guildOnly: true };
@@ -51,7 +57,9 @@ function parseDiscordChannelInput(raw: string): {
if (!channel) {
return guild ? { guild: guild.trim(), guildOnly: true } : {};
}
if (guild && /^\d+$/.test(guild)) return { guildId: guild, channel };
if (guild && /^\d+$/.test(guild)) {
return { guildId: guild, channel };
}
return { guild, channel };
}
return { guild: trimmed, guildOnly: true };
@@ -100,7 +108,9 @@ async function fetchChannel(
channelId: string,
): Promise<DiscordChannelSummary | null> {
const raw = await fetchDiscord(`/channels/${channelId}`, token, fetcher);
if (!raw || !("guild_id" in raw)) return null;
if (!raw || !("guild_id" in raw)) {
return null;
}
return {
id: raw.id,
name: "name" in raw ? (raw.name ?? "") : "",
@@ -110,7 +120,9 @@ async function fetchChannel(
}
function preferActiveMatch(candidates: DiscordChannelSummary[]): DiscordChannelSummary | undefined {
if (candidates.length === 0) return undefined;
if (candidates.length === 0) {
return undefined;
}
const scored = candidates.map((channel) => {
const isThread = channel.type === 11 || channel.type === 12;
const archived = Boolean(channel.archived);
@@ -126,7 +138,9 @@ function resolveGuildByName(
input: string,
): DiscordGuildSummary | undefined {
const slug = normalizeDiscordSlug(input);
if (!slug) return undefined;
if (!slug) {
return undefined;
}
return guilds.find((guild) => guild.slug === slug);
}
@@ -136,17 +150,20 @@ export async function resolveDiscordChannelAllowlist(params: {
fetcher?: typeof fetch;
}): Promise<DiscordChannelResolution[]> {
const token = normalizeDiscordToken(params.token);
if (!token)
if (!token) {
return params.entries.map((input) => ({
input,
resolved: false,
}));
}
const fetcher = params.fetcher ?? fetch;
const guilds = await listGuilds(token, fetcher);
const channelsByGuild = new Map<string, Promise<DiscordChannelSummary[]>>();
const getChannels = (guildId: string) => {
const existing = channelsByGuild.get(guildId);
if (existing) return existing;
if (existing) {
return existing;
}
const promise = listGuildChannels(token, fetcher, guildId);
channelsByGuild.set(guildId, promise);
return promise;