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

@@ -3,8 +3,12 @@ import { Buffer } from "node:buffer";
const CLOSE_REASON_MAX_BYTES = 120;
export function truncateCloseReason(reason: string, maxBytes = CLOSE_REASON_MAX_BYTES): string {
if (!reason) return "invalid handshake";
if (!reason) {
return "invalid handshake";
}
const buf = Buffer.from(reason);
if (buf.length <= maxBytes) return reason;
if (buf.length <= maxBytes) {
return reason;
}
return buf.subarray(0, maxBytes).toString();
}

View File

@@ -18,7 +18,9 @@ export function createGatewayPluginRequestHandler(params: {
return async (req, res) => {
const routes = registry.httpRoutes ?? [];
const handlers = registry.httpHandlers ?? [];
if (routes.length === 0 && handlers.length === 0) return false;
if (routes.length === 0 && handlers.length === 0) {
return false;
}
if (routes.length > 0) {
const url = new URL(req.url ?? "/", "http://localhost");
@@ -42,7 +44,9 @@ export function createGatewayPluginRequestHandler(params: {
for (const entry of handlers) {
try {
const handled = await entry.handler(req, res);
if (handled) return true;
if (handled) {
return true;
}
} catch (err) {
log.warn(`plugin http handler failed (${entry.pluginId}): ${String(err)}`);
if (!res.headersSent) {

View File

@@ -95,7 +95,9 @@ export function attachGatewayWsConnectionHandler(params: {
let lastFrameId: string | undefined;
const setCloseCause = (cause: string, meta?: Record<string, unknown>) => {
if (!closeCause) closeCause = cause;
if (!closeCause) {
closeCause = cause;
}
if (meta && Object.keys(meta).length > 0) {
closeMeta = { ...closeMeta, ...meta };
}
@@ -125,10 +127,14 @@ export function attachGatewayWsConnectionHandler(params: {
});
const close = (code = 1000, reason?: string) => {
if (closed) return;
if (closed) {
return;
}
closed = true;
clearTimeout(handshakeTimer);
if (client) clients.delete(client);
if (client) {
clients.delete(client);
}
try {
socket.close(code, reason);
} catch {

View File

@@ -61,10 +61,14 @@ const DEVICE_SIGNATURE_SKEW_MS = 10 * 60 * 1000;
function resolveHostName(hostHeader?: string): string {
const host = (hostHeader ?? "").trim().toLowerCase();
if (!host) return "";
if (!host) {
return "";
}
if (host.startsWith("[")) {
const end = host.indexOf("]");
if (end !== -1) return host.slice(1, end);
if (end !== -1) {
return host.slice(1, end);
}
}
const [name] = host.split(":");
return name ?? "";
@@ -229,7 +233,9 @@ export function attachGatewayWsMessageHandler(params: {
const isWebchatConnect = (p: ConnectParams | null | undefined) => isWebchatClient(p?.client);
socket.on("message", async (data) => {
if (isClosed()) return;
if (isClosed()) {
return;
}
const text = rawDataToString(data);
try {
const parsed = JSON.parse(text);
@@ -681,30 +687,40 @@ export function attachGatewayWsMessageHandler(params: {
const isPaired = paired?.publicKey === devicePublicKey;
if (!isPaired) {
const ok = await requirePairing("not-paired");
if (!ok) return;
if (!ok) {
return;
}
} else {
const allowedRoles = new Set(
Array.isArray(paired.roles) ? paired.roles : paired.role ? [paired.role] : [],
);
if (allowedRoles.size === 0) {
const ok = await requirePairing("role-upgrade", paired);
if (!ok) return;
if (!ok) {
return;
}
} else if (!allowedRoles.has(role)) {
const ok = await requirePairing("role-upgrade", paired);
if (!ok) return;
if (!ok) {
return;
}
}
const pairedScopes = Array.isArray(paired.scopes) ? paired.scopes : [];
if (scopes.length > 0) {
if (pairedScopes.length === 0) {
const ok = await requirePairing("scope-upgrade", paired);
if (!ok) return;
if (!ok) {
return;
}
} else {
const allowedScopes = new Set(pairedScopes);
const missingScope = scopes.find((scope) => !allowedScopes.has(scope));
if (missingScope) {
const ok = await requirePairing("scope-upgrade", paired);
if (!ok) return;
if (!ok) {
return;
}
}
}
}
@@ -828,7 +844,9 @@ export function attachGatewayWsMessageHandler(params: {
const instanceIdRaw = connectParams.client.instanceId;
const instanceId = typeof instanceIdRaw === "string" ? instanceIdRaw.trim() : "";
const nodeIdsForPairing = new Set<string>([nodeSession.nodeId]);
if (instanceId) nodeIdsForPairing.add(instanceId);
if (instanceId) {
nodeIdsForPairing.add(instanceId);
}
for (const nodeId of nodeIdsForPairing) {
void updatePairedNodeMetadata(nodeId, {
lastConnectedAtMs: nodeSession.connectedAtMs,