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

@@ -13,9 +13,15 @@ function stripQuotes(value: string): string {
}
function coerceFrontmatterValue(value: unknown): string | undefined {
if (value === null || value === undefined) return undefined;
if (typeof value === "string") return value.trim();
if (typeof value === "number" || typeof value === "boolean") return String(value);
if (value === null || value === undefined) {
return undefined;
}
if (typeof value === "string") {
return value.trim();
}
if (typeof value === "number" || typeof value === "boolean") {
return String(value);
}
if (typeof value === "object") {
try {
return JSON.stringify(value);
@@ -29,13 +35,19 @@ function coerceFrontmatterValue(value: unknown): string | undefined {
function parseYamlFrontmatter(block: string): ParsedFrontmatter | null {
try {
const parsed = YAML.parse(block) as unknown;
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
return null;
}
const result: ParsedFrontmatter = {};
for (const [rawKey, value] of Object.entries(parsed as Record<string, unknown>)) {
const key = rawKey.trim();
if (!key) continue;
if (!key) {
continue;
}
const coerced = coerceFrontmatterValue(value);
if (coerced === undefined) continue;
if (coerced === undefined) {
continue;
}
result[key] = coerced;
}
return result;
@@ -50,7 +62,9 @@ function extractMultiLineValue(
): { value: string; linesConsumed: number } {
const startLine = lines[startIndex];
const match = startLine.match(/^([\w-]+):\s*(.*)$/);
if (!match) return { value: "", linesConsumed: 1 };
if (!match) {
return { value: "", linesConsumed: 1 };
}
const inlineValue = match[2].trim();
if (inlineValue) {
@@ -118,14 +132,20 @@ function parseLineFrontmatter(block: string): ParsedFrontmatter {
export function parseFrontmatterBlock(content: string): ParsedFrontmatter {
const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
if (!normalized.startsWith("---")) return {};
if (!normalized.startsWith("---")) {
return {};
}
const endIndex = normalized.indexOf("\n---", 3);
if (endIndex === -1) return {};
if (endIndex === -1) {
return {};
}
const block = normalized.slice(4, endIndex);
const lineParsed = parseLineFrontmatter(block);
const yamlParsed = parseYamlFrontmatter(block);
if (yamlParsed === null) return lineParsed;
if (yamlParsed === null) {
return lineParsed;
}
const merged: ParsedFrontmatter = { ...yamlParsed };
for (const [key, value] of Object.entries(lineParsed)) {