Skip to content

list-invariant ​

A list marked /** @sorted */ whose elements are out of order, or a list marked /** @unique */ that names an element twice; and either tag where the checker can't verify it.

Why: a list that must stay sorted (a merge order, a hash input, a list searched by bisection) or free of repeats usually says so only in a comment. Adding at the end is what an agent does, and what a merge does when two branches each add one. An adopter's list of encoding features had to stay sorted, said so in a comment, and still got marchTogether after pub. The tag states the rule where the checker verifies it, on every run. Guide: Enums.

✕ Rejectedlist-invariant
ts
/**
 * Encoding features: each one adds a field to a snapshot, in this order.
 * @sorted @unique
 */
export const FEATURES = Object.freeze(["library", "pub", "marchTogether", "scoutResume"]);
text
"marchTogether" is out of order in `FEATURES`, which is `@sorted`: it comes after "pub"
  help: Move it to its sorted place: between "library" and "pub". ...
✓ Accepted0 diagnostics
ts
/**
 * Encoding features: each one adds a field to a snapshot, in this order.
 * @sorted @unique
 */
export const FEATURES = Object.freeze(["library", "marchTogether", "pub", "scoutResume"]);

What counts ​

  • Where: the tag goes in the comment right before a module-level const (exported or not). The comment may hold other text and other tags. The value is an array literal that nothing can change afterwards: [...] as const or Object.freeze([...]), also with a type annotation (const X: readonly string[] = Object.freeze([...])). A plain [...] is reported, since code could sort or push to it after the check.
  • What: string literals or number literals, not both. Comments between the elements are fine.
  • @sorted is ascending: numbers by value, strings as sort() orders them, by UTF-16 code units ("Zed" before "alpha"). Equal neighbours are fine; add @unique to forbid them. The first element out of order is reported, with the place it belongs.
  • @unique reports the second of two equal elements. On a code table (an as const or frozen object), @unique means its values are all different, and duplicate-code-value reports two that aren't.

What the rule can't see ​

A list built at run time (names.toSorted(), a spread of another list) has no literal elements to check, so the tag is reported there. Sort it once where it is declared, or check it in a test.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra