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

@@ -27,22 +27,32 @@ function normalizeRole(role: string): string {
}
function normalizeScopes(scopes: string[] | undefined): string[] {
if (!Array.isArray(scopes)) return [];
if (!Array.isArray(scopes)) {
return [];
}
const out = new Set<string>();
for (const scope of scopes) {
const trimmed = scope.trim();
if (trimmed) out.add(trimmed);
if (trimmed) {
out.add(trimmed);
}
}
return [...out].toSorted();
}
function readStore(filePath: string): DeviceAuthStore | null {
try {
if (!fs.existsSync(filePath)) return null;
if (!fs.existsSync(filePath)) {
return null;
}
const raw = fs.readFileSync(filePath, "utf8");
const parsed = JSON.parse(raw) as DeviceAuthStore;
if (parsed?.version !== 1 || typeof parsed.deviceId !== "string") return null;
if (!parsed.tokens || typeof parsed.tokens !== "object") return null;
if (parsed?.version !== 1 || typeof parsed.deviceId !== "string") {
return null;
}
if (!parsed.tokens || typeof parsed.tokens !== "object") {
return null;
}
return parsed;
} catch {
return null;
@@ -66,11 +76,17 @@ export function loadDeviceAuthToken(params: {
}): DeviceAuthEntry | null {
const filePath = resolveDeviceAuthPath(params.env);
const store = readStore(filePath);
if (!store) return null;
if (store.deviceId !== params.deviceId) return null;
if (!store) {
return null;
}
if (store.deviceId !== params.deviceId) {
return null;
}
const role = normalizeRole(params.role);
const entry = store.tokens[role];
if (!entry || typeof entry.token !== "string") return null;
if (!entry || typeof entry.token !== "string") {
return null;
}
return entry;
}
@@ -110,9 +126,13 @@ export function clearDeviceAuthToken(params: {
}): void {
const filePath = resolveDeviceAuthPath(params.env);
const store = readStore(filePath);
if (!store || store.deviceId !== params.deviceId) return;
if (!store || store.deviceId !== params.deviceId) {
return;
}
const role = normalizeRole(params.role);
if (!store.tokens[role]) return;
if (!store.tokens[role]) {
return;
}
const next: DeviceAuthStore = {
version: 1,
deviceId: store.deviceId,