Skip to content

Commit 4f58387

Browse files
committed
docs(claude): reference joinAnd / joinOr helpers in Error Messages
Point readers at @socketsecurity/lib/arrays' list-formatting helpers from CLAUDE.md (one-line rule) and the worked-examples references doc (dedicated section). Hand-joining with commas silently breaks on one- or two-item lists and skips the Oxford comma; Intl.ListFormat (wrapped by joinAnd / joinOr) handles both.
1 parent 36a83cf commit 4f58387

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Rules for every message:
112112
- On a collision, name **both** sides, not just the second one found.
113113
- Suggest, don't auto-correct. Silently fixing state hides the bug next time.
114114
- Bloat check: if removing a word keeps the information, drop it.
115+
- For allowed-set / conflict lists, use `joinAnd` / `joinOr` from `@socketsecurity/lib/arrays``must be one of: ${joinOr(allowed)}` reads better than a hand-formatted list.
115116

116117
Examples:
117118

docs/references/error-messages.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ terse keeps the assertion readable when you skim the code.
8080
-`The value provided for "timeout" is invalid because timeouts must be positive numbers and the value you provided was not a positive number.`
8181
-`timeout must be a positive number (saw: -5)`
8282

83+
## Formatting lists of values
84+
85+
When the error needs to show an allowed set, a list of conflicting
86+
records, or multiple missing fields, use the list formatters from
87+
`@socketsecurity/lib/arrays` rather than hand-joining with commas:
88+
89+
- `joinAnd(['a', 'b', 'c'])``"a, b, and c"` — for conjunctions ("missing foo, bar, and baz")
90+
- `joinOr(['npm', 'pypi', 'maven'])``"npm, pypi, or maven"` — for disjunctions ("must be one of: …")
91+
92+
Both wrap `Intl.ListFormat`, so the Oxford comma and one-/two-item cases come out right for free (`joinOr(['a'])``"a"`; `joinOr(['a', 'b'])``"a or b"`).
93+
94+
-`--reach-ecosystems must be one of: npm, pypi, maven (saw: "foo")` — hand-joined, breaks if the list has one or two entries.
95+
-`` `--reach-ecosystems must be one of: ${joinOr(ALLOWED)} (saw: "foo")` ``
96+
-`missing keys: filename slug title` — no separators, no grammar.
97+
-`` `missing keys: ${joinAnd(missing)}` ```"missing keys: filename, slug, and title"`
98+
99+
Use `joinOr` whenever the error is "must be one of X", `joinAnd` whenever it's "all of X are required / missing / in conflict".
100+
83101
## Voice & tone
84102

85103
- Imperative for the fix: `rename`, `add`, `remove`, `set`.

0 commit comments

Comments
 (0)