Skip to content

Commit 4bedeff

Browse files
committed
docs: add null-prototype object pattern guidelines to CLAUDE.md
1 parent 5224604 commit 4bedeff

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ Use these standardized patterns for consistency across all Socket projects:
255255
- ❌ FORBIDDEN: `{ foo: 'bar', __proto__: null }` (wrong order)
256256
- ❌ FORBIDDEN: `{ ...options, __proto__: null }` (wrong order)
257257
- Use `Map` for dynamic collections
258+
- **Null-prototype objects**:
259+
- ✅ CORRECT: `{ __proto__: null, key: 'value' }` (object literal with properties)
260+
- ✅ CORRECT: `{ __proto__: null, ...options }` (spread pattern)
261+
- ✅ CORRECT: `const obj = Object.create(null)` (empty object, populate separately)
262+
- ❌ WRONG: `const obj = { __proto__: null }` (empty object literal - use `Object.create(null)` instead)
263+
- **Rationale**: Use `Object.create(null)` only for empty null-prototype objects; object literals with `__proto__: null` are fine when they have properties
258264
- **Array destructuring**: Use object notation for tuple access
259265
- ✅ CORRECT: `{ 0: key, 1: data }`
260266
- ❌ AVOID: `[key, data]`

0 commit comments

Comments
 (0)