Skip to content

Commit 4d56689

Browse files
Eric Wheelerdaniel-lxs
authored andcommitted
docs: add rules for using safeWriteJson
Add concise rules for using safeWriteJson instead of JSON.stringify with file operations to ensure atomic writes and prevent data corruption. Signed-off-by: Eric Wheeler <[email protected]>
1 parent dd54108 commit 4d56689

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# JSON File Writing Must Be Atomic
2+
3+
- You MUST use `safeWriteJson(filePath: string, data: any): Promise<void>` from `src/utils/safeWriteJson.ts` instead of `JSON.stringify` with file-write operations
4+
- `safeWriteJson` will create parent directories if necessary, so do not call `mkdir` prior to `safeWriteJson`
5+
- `safeWriteJson` prevents data corruption via atomic writes with locking and streams the write to minimize memory footprint
6+
- Test files are exempt from this rule

0 commit comments

Comments
 (0)