Address review: safer save, stricter load and id parsing

- save() follows symlinks, keeps permissions, uses a unique temp file and cleans it up on failure
- load() rejects entries that aren't {id, text, done}
- add() finds the max id with reduce (no spread limit)
- CLI accepts only plain digits as ids and reports save errors readably
- Ignore *.tmp

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
christianandClaude Opus 5.5 committed 2026-10-21 00:26:22 +02:00
1 parent ba17376132
commit 8dc5194438
5 files changed
+95 -13

No files matched your search

+8 -2
View File
@@ -11,8 +11,8 @@ function fail(message) {
}
function parseId(todos, arg) {
if (!/^\d+$/.test(arg ?? "")) fail(`Invalid id: ${arg ?? "(missing)"}\n${USAGE}`);
const id = Number(arg);
if (arg === undefined || !Number.isInteger(id)) fail(`Invalid id: ${arg ?? "(missing)"}\n${USAGE}`);
if (!has(todos, id)) fail(`No todo with id ${id}`);
return id;
}
@@ -41,5 +41,11 @@ switch (cmd) {
break;
}
if (cmd !== "ls") save(FILE, todos);
if (cmd !== "ls") {
try {
save(FILE, todos);
} catch (err) {
fail(err.message);
}
}
console.log(format(todos));