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
+3 -1
View File
@@ -10,7 +10,9 @@ import type {
export const DEFAULT_ACCOUNT_ID = "default";
function readFileIfExists(filePath: string | undefined): string | undefined {
if (!filePath) return undefined;
if (!filePath) {
return undefined;
}
try {
return fs.readFileSync(filePath, "utf-8").trim();
} catch {
+6 -2
View File
@@ -59,7 +59,9 @@ export async function deliverLineAutoReply(params: {
let replyTokenUsed = params.replyTokenUsed;
const pushLineMessages = async (messages: messagingApi.Message[]): Promise<void> => {
if (messages.length === 0) return;
if (messages.length === 0) {
return;
}
for (let i = 0; i < messages.length; i += 5) {
await deps.pushMessagesLine(to, messages.slice(i, i + 5), {
accountId,
@@ -71,7 +73,9 @@ export async function deliverLineAutoReply(params: {
messages: messagingApi.Message[],
allowReplyToken: boolean,
): Promise<void> => {
if (messages.length === 0) return;
if (messages.length === 0) {
return;
}
let remaining = messages;
if (allowReplyToken && replyToken && !replyTokenUsed) {
+18 -6
View File
@@ -6,8 +6,12 @@ export type NormalizedAllowFrom = {
function normalizeAllowEntry(value: string | number): string {
const trimmed = String(value).trim();
if (!trimmed) return "";
if (trimmed === "*") return "*";
if (!trimmed) {
return "";
}
if (trimmed === "*") {
return "*";
}
return trimmed.replace(/^line:(?:user:)?/i, "");
}
@@ -31,7 +35,9 @@ export const normalizeAllowFromWithStore = (params: {
export const firstDefined = <T>(...values: Array<T | undefined>) => {
for (const value of values) {
if (typeof value !== "undefined") return value;
if (typeof value !== "undefined") {
return value;
}
}
return undefined;
};
@@ -41,8 +47,14 @@ export const isSenderAllowed = (params: {
senderId?: string;
}): boolean => {
const { allow, senderId } = params;
if (!allow.hasEntries) return false;
if (allow.hasWildcard) return true;
if (!senderId) return false;
if (!allow.hasEntries) {
return false;
}
if (allow.hasWildcard) {
return true;
}
if (!senderId) {
return false;
}
return allow.entries.includes(senderId);
};
+12 -4
View File
@@ -87,7 +87,9 @@ async function sendLinePairingReply(params: {
channel: "line",
id: senderId,
});
if (!created) return;
if (!created) {
return;
}
logVerbose(`line pairing request sender=${senderId}`);
const idLabel = (() => {
try {
@@ -219,7 +221,9 @@ async function handleMessageEvent(event: MessageEvent, context: LineHandlerConte
const { cfg, account, runtime, mediaMaxBytes, processMessage } = context;
const message = event.message;
if (!(await shouldProcessLineEvent(event, context))) return;
if (!(await shouldProcessLineEvent(event, context))) {
return;
}
// Download media if applicable
const allMedia: MediaRef[] = [];
@@ -290,14 +294,18 @@ async function handlePostbackEvent(
const data = event.postback.data;
logVerbose(`line: received postback: ${data}`);
if (!(await shouldProcessLineEvent(event, context))) return;
if (!(await shouldProcessLineEvent(event, context))) {
return;
}
const postbackContext = await buildLinePostbackContext({
event,
cfg: context.cfg,
account: context.account,
});
if (!postbackContext) return;
if (!postbackContext) {
return;
}
await context.processMessage(postbackContext);
}
+3 -1
View File
@@ -335,7 +335,9 @@ export async function buildLinePostbackContext(params: {
const timestamp = event.timestamp;
const rawData = event.postback?.data?.trim() ?? "";
if (!rawData) return null;
if (!rawData) {
return null;
}
let rawBody = rawData;
if (rawData.includes("line.action=")) {
const params = new URLSearchParams(rawData);
+6 -2
View File
@@ -852,8 +852,12 @@ export function createAgendaCard(params: {
// Secondary info line
const secondaryParts: string[] = [];
if (event.location) secondaryParts.push(event.location);
if (event.calendar) secondaryParts.push(event.calendar);
if (event.location) {
secondaryParts.push(event.location);
}
if (event.calendar) {
secondaryParts.push(event.calendar);
}
if (secondaryParts.length > 0) {
detailContents.push({
+6 -2
View File
@@ -16,7 +16,9 @@ const lineHttpRoutes = new Map<string, LineHttpRequestHandler>();
export function normalizeLineWebhookPath(path?: string | null): string {
const trimmed = path?.trim();
if (!trimmed) return "/line/webhook";
if (!trimmed) {
return "/line/webhook";
}
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
}
@@ -39,7 +41,9 @@ export async function handleLineHttpRequest(
): Promise<boolean> {
const url = new URL(req.url ?? "/", "http://localhost");
const handler = lineHttpRoutes.get(url.pathname);
if (!handler) return false;
if (!handler) {
return false;
}
await handler(req, res);
return true;
}
+27 -9
View File
@@ -80,8 +80,12 @@ function parseTableRow(row: string): string[] {
.map((cell) => cell.trim())
.filter((cell, index, arr) => {
// Filter out empty cells at start/end (from leading/trailing pipes)
if (index === 0 && cell === "") return false;
if (index === arr.length - 1 && cell === "") return false;
if (index === 0 && cell === "") {
return false;
}
if (index === arr.length - 1 && cell === "") {
return false;
}
return true;
});
}
@@ -94,7 +98,9 @@ export function convertTableToFlexBubble(table: MarkdownTable): FlexBubble {
value: string | undefined,
): { text: string; bold: boolean; hasMarkup: boolean } => {
const raw = value?.trim() ?? "";
if (!raw) return { text: "-", bold: false, hasMarkup: false };
if (!raw) {
return { text: "-", bold: false, hasMarkup: false };
}
let hasMarkup = false;
const stripped = raw.replace(/\*\*(.+?)\*\*/g, (_, inner) => {
@@ -417,17 +423,29 @@ export function processLineMessage(text: string): ProcessedLineMessage {
export function hasMarkdownToConvert(text: string): boolean {
// Check for tables
MARKDOWN_TABLE_REGEX.lastIndex = 0;
if (MARKDOWN_TABLE_REGEX.test(text)) return true;
if (MARKDOWN_TABLE_REGEX.test(text)) {
return true;
}
// Check for code blocks
MARKDOWN_CODE_BLOCK_REGEX.lastIndex = 0;
if (MARKDOWN_CODE_BLOCK_REGEX.test(text)) return true;
if (MARKDOWN_CODE_BLOCK_REGEX.test(text)) {
return true;
}
// Check for other markdown patterns
if (/\*\*[^*]+\*\*/.test(text)) return true; // bold
if (/~~[^~]+~~/.test(text)) return true; // strikethrough
if (/^#{1,6}\s+/m.test(text)) return true; // headers
if (/^>\s+/m.test(text)) return true; // blockquotes
if (/\*\*[^*]+\*\*/.test(text)) {
return true;
} // bold
if (/~~[^~]+~~/.test(text)) {
return true;
} // strikethrough
if (/^#{1,6}\s+/m.test(text)) {
return true;
} // headers
if (/^>\s+/m.test(text)) {
return true;
} // blockquotes
return false;
}
+9 -3
View File
@@ -105,7 +105,9 @@ function startLineLoadingKeepalive(params: {
let stopped = false;
const trigger = () => {
if (stopped) return;
if (stopped) {
return;
}
void showLoadingAnimation(params.userId, {
accountId: params.accountId,
loadingSeconds,
@@ -116,7 +118,9 @@ function startLineLoadingKeepalive(params: {
const timer = setInterval(trigger, intervalMs);
return () => {
if (stopped) return;
if (stopped) {
return;
}
stopped = true;
clearInterval(timer);
};
@@ -154,7 +158,9 @@ export async function monitorLineProvider(
runtime,
config,
onMessage: async (ctx) => {
if (!ctx) return;
if (!ctx) {
return;
}
const { ctxPayload, replyToken, route } = ctx;
+6 -2
View File
@@ -32,12 +32,16 @@ export async function probeLineBot(
}
function withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T> {
if (!timeoutMs || timeoutMs <= 0) return promise;
if (!timeoutMs || timeoutMs <= 0) {
return promise;
}
let timer: NodeJS.Timeout | null = null;
const timeout = new Promise<T>((_, reject) => {
timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
});
return Promise.race([promise, timeout]).finally(() => {
if (timer) clearTimeout(timer);
if (timer) {
clearTimeout(timer);
}
});
}
+3 -1
View File
@@ -42,7 +42,9 @@ function resolveToken(
explicit: string | undefined,
params: { accountId: string; channelAccessToken: string },
): string {
if (explicit?.trim()) return explicit.trim();
if (explicit?.trim()) {
return explicit.trim();
}
if (!params.channelAccessToken) {
throw new Error(
`LINE channel access token missing for account "${params.accountId}" (set channels.line.channelAccessToken or LINE_CHANNEL_ACCESS_TOKEN).`,
+12 -4
View File
@@ -35,7 +35,9 @@ function resolveToken(
explicit: string | undefined,
params: { accountId: string; channelAccessToken: string },
): string {
if (explicit?.trim()) return explicit.trim();
if (explicit?.trim()) {
return explicit.trim();
}
if (!params.channelAccessToken) {
throw new Error(
`LINE channel access token missing for account "${params.accountId}" (set channels.line.channelAccessToken or LINE_CHANNEL_ACCESS_TOKEN).`,
@@ -46,7 +48,9 @@ function resolveToken(
function normalizeTarget(to: string): string {
const trimmed = to.trim();
if (!trimmed) throw new Error("Recipient is required for LINE sends");
if (!trimmed) {
throw new Error("Recipient is required for LINE sends");
}
// Strip internal prefixes
let normalized = trimmed
@@ -55,7 +59,9 @@ function normalizeTarget(to: string): string {
.replace(/^line:user:/i, "")
.replace(/^line:/i, "");
if (!normalized) throw new Error("Recipient is required for LINE sends");
if (!normalized) {
throw new Error("Recipient is required for LINE sends");
}
return normalized;
}
@@ -91,7 +97,9 @@ export function createLocationMessage(location: {
}
function logLineHttpError(err: unknown, context: string): void {
if (!err || typeof err !== "object") return;
if (!err || typeof err !== "object") {
return;
}
const { status, statusText, body } = err as {
status?: number;
statusText?: string;
+3 -1
View File
@@ -14,7 +14,9 @@ function readRawBody(req: Request): string | null {
const rawBody =
(req as { rawBody?: string | Buffer }).rawBody ??
(typeof req.body === "string" || Buffer.isBuffer(req.body) ? req.body : null);
if (!rawBody) return null;
if (!rawBody) {
return null;
}
return Buffer.isBuffer(rawBody) ? rawBody.toString("utf-8") : rawBody;
}