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,13 +6,17 @@ import type { AuthProfileIdRepairResult, AuthProfileStore } from "./types.js";
function getProfileSuffix(profileId: string): string {
const idx = profileId.indexOf(":");
if (idx < 0) return "";
if (idx < 0) {
return "";
}
return profileId.slice(idx + 1);
}
function isEmailLike(value: string): boolean {
const trimmed = value.trim();
if (!trimmed) return false;
if (!trimmed) {
return false;
}
return trimmed.includes("@") && trimmed.includes(".");
}
@@ -24,7 +28,9 @@ export function suggestOAuthProfileIdForLegacyDefault(params: {
}): string | null {
const providerKey = normalizeProviderId(params.provider);
const legacySuffix = getProfileSuffix(params.legacyProfileId);
if (legacySuffix !== "default") return null;
if (legacySuffix !== "default") {
return null;
}
const legacyCfg = params.cfg?.auth?.profiles?.[params.legacyProfileId];
if (
@@ -38,27 +44,39 @@ export function suggestOAuthProfileIdForLegacyDefault(params: {
const oauthProfiles = listProfilesForProvider(params.store, providerKey).filter(
(id) => params.store.profiles[id]?.type === "oauth",
);
if (oauthProfiles.length === 0) return null;
if (oauthProfiles.length === 0) {
return null;
}
const configuredEmail = legacyCfg?.email?.trim();
if (configuredEmail) {
const byEmail = oauthProfiles.find((id) => {
const cred = params.store.profiles[id];
if (!cred || cred.type !== "oauth") return false;
if (!cred || cred.type !== "oauth") {
return false;
}
const email = cred.email?.trim();
return email === configuredEmail || id === `${providerKey}:${configuredEmail}`;
});
if (byEmail) return byEmail;
if (byEmail) {
return byEmail;
}
}
const lastGood = params.store.lastGood?.[providerKey] ?? params.store.lastGood?.[params.provider];
if (lastGood && oauthProfiles.includes(lastGood)) return lastGood;
if (lastGood && oauthProfiles.includes(lastGood)) {
return lastGood;
}
const nonLegacy = oauthProfiles.filter((id) => id !== params.legacyProfileId);
if (nonLegacy.length === 1) return nonLegacy[0] ?? null;
if (nonLegacy.length === 1) {
return nonLegacy[0] ?? null;
}
const emailLike = nonLegacy.filter((id) => isEmailLike(getProfileSuffix(id)));
if (emailLike.length === 1) return emailLike[0] ?? null;
if (emailLike.length === 1) {
return emailLike[0] ?? null;
}
return null;
}
@@ -107,17 +125,25 @@ export function repairOAuthProfileIdMismatch(params: {
const providerKey = normalizeProviderId(params.provider);
const nextOrder = (() => {
const order = params.cfg.auth?.order;
if (!order) return undefined;
if (!order) {
return undefined;
}
const resolvedKey = Object.keys(order).find((key) => normalizeProviderId(key) === providerKey);
if (!resolvedKey) return order;
if (!resolvedKey) {
return order;
}
const existing = order[resolvedKey];
if (!Array.isArray(existing)) return order;
if (!Array.isArray(existing)) {
return order;
}
const replaced = existing
.map((id) => (id === legacyProfileId ? toProfileId : id))
.filter((id): id is string => typeof id === "string" && id.trim().length > 0);
const deduped: string[] = [];
for (const entry of replaced) {
if (!deduped.includes(entry)) deduped.push(entry);
if (!deduped.includes(entry)) {
deduped.push(entry);
}
}
return { ...order, [resolvedKey]: deduped };
})();