Skip to content

Commit f42627d

Browse files
committed
chore(claude): document Set constructor argument sort rule
`new Set([...])` and `new SafeSet([...])` arguments are order-insensitive at runtime, so the source-order convention is alphanumeric — same rationale as Array literals (predictable diffs, no merge conflicts on insertions). Synced from socket-lib's canonical Sorting section.
1 parent a2df418 commit f42627d

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Sort lists alphanumerically (literal byte order, ASCII before letters). Apply th
202202
- **Import specifiers** — sort named imports inside a single statement: `import { encrypt, randomDataKey, wrapKey } from './crypto.mts'`. Imports that say `import type` follow the same rule. Statement _order_ is the project's existing convention (`node:` → external → local → types) — that's separate from specifier order _within_ a statement.
203203
- **Method / function source placement** — within a module, sort top-level functions alphabetically. Convention: private functions (lowercase / un-exported) sort first, exported functions second. The first-line `export` keyword is the divider.
204204
- **Array literals** — when the array is a config list, allowlist, or set-like collection. Position-bearing arrays (e.g. argv, anything where index matters semantically) keep their meaningful order.
205+
- **`Set` constructor arguments**`new Set([...])` and `new SafeSet([...])` literals. The runtime is order-insensitive, so source order is alphanumeric. Same rationale as Array literals: predictable diffs, no merge conflicts on insertions.
205206

206207
When in doubt, sort. The cost of a sorted list that didn't need to be is approximately zero; the cost of an unsorted list that did need to be is a merge conflict.
207208

0 commit comments

Comments
 (0)