mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:03:29 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user