revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+28 -28
View File
@@ -11,22 +11,22 @@
export interface PatchResult {
/** The new file content, with surgical edits applied. */
content: string;
content: string
/** Keys that we could not patch surgically (missing or unusual format). */
unpatchedKeys: string[];
unpatchedKeys: string[]
}
function escapeRegExp(s: string): string {
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
function escapeForQuote(value: string, quote: '"' | "'"): string {
// Escape backslashes first, then the chosen quote. Newlines/tabs are
// preserved as escape sequences so we don't break the JSON5 parser.
let out = value.replace(/\\/g, "\\\\");
out = out.replace(new RegExp(quote, "g"), `\\${quote}`);
out = out.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
return out;
let out = value.replace(/\\/g, '\\\\')
out = out.replace(new RegExp(quote, 'g'), `\\${quote}`)
out = out.replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t')
return out
}
/**
@@ -39,40 +39,40 @@ export function patchJson5(
original: Record<string, string>,
updated: Record<string, string>,
): PatchResult {
let result = raw;
const unpatchedKeys: string[] = [];
let result = raw
const unpatchedKeys: string[] = []
for (const [key, newVal] of Object.entries(updated)) {
if (!(key in original)) {
// Key did not exist on disk — append/merge logic is the caller's job.
unpatchedKeys.push(key);
continue;
unpatchedKeys.push(key)
continue
}
if (original[key] === newVal) continue;
if (original[key] === newVal) continue
const keyPattern = `(['"]?)${escapeRegExp(key)}\\1\\s*:\\s*(["'])((?:\\\\.|(?!\\2).)*)\\2`;
const re = new RegExp(keyPattern);
const idx = result.search(re);
const keyPattern = `(['"]?)${escapeRegExp(key)}\\1\\s*:\\s*(["'])((?:\\\\.|(?!\\2).)*)\\2`
const re = new RegExp(keyPattern)
const idx = result.search(re)
if (idx < 0) {
unpatchedKeys.push(key);
continue;
unpatchedKeys.push(key)
continue
}
const match = re.exec(result);
const match = re.exec(result)
if (!match) {
unpatchedKeys.push(key);
continue;
unpatchedKeys.push(key)
continue
}
const valueQuote = match[2] as '"' | "'";
const oldValueLen = match[3].length;
const fullLen = match[0].length;
const valueQuote = match[2] as '"' | "'"
const oldValueLen = match[3].length
const fullLen = match[0].length
// prefix keeps everything up to and including the opening value quote
const prefix = match[0].slice(0, fullLen - oldValueLen - 1);
const escaped = escapeForQuote(newVal, valueQuote);
const replacement = prefix + escaped + valueQuote;
const prefix = match[0].slice(0, fullLen - oldValueLen - 1)
const escaped = escapeForQuote(newVal, valueQuote)
const replacement = prefix + escaped + valueQuote
result = result.slice(0, idx) + replacement + result.slice(idx + fullLen);
result = result.slice(0, idx) + replacement + result.slice(idx + fullLen)
}
return { content: result, unpatchedKeys };
return { content: result, unpatchedKeys }
}