Skip to content

inline-member-set ​

The same value is tested inline against members of one closed set in more than one function, and the sets share members: u.afterJob === Job.DEPOSIT || u.afterJob === Job.MINE in one check, afterJob >= Job.MOVE && afterJob <= Job.IGNITE || … in the save reader. Both places are reported, each naming the other and what differs. Reported by safe-ts check only, which sees the whole program; the editor and the lint plugin check one file at a time.

Why: a set written out by hand in two places is two sets. One gets the member added, the other doesn't, and nothing compares them. An adopter's "jobs a unit keeps while away" was copied four times: DEPOSIT || MINE in one invariant check, DEPOSIT alone in two others, and a range of codes in the save reader. A farmer on a toilet trip kept FARM; the checks refused him, and the world no longer loaded. One exported set (or one match) that the reader, the writer and the checks all use can't drift. Guide: Enums.

❌ Rejected: the same set, twice, and the copies differ (two files, so not checked here)

ts
// invariants.ts
export function keptResume(u: Unit): boolean {
  return u.afterJob === Job.DEPOSIT || u.afterJob === Job.MINE;
}

// save.ts
export function validAfterJob(afterJob: Job): boolean {
  return (afterJob >= Job.MOVE && afterJob <= Job.IGNITE) || afterJob === Job.STAFF;
}
text
`u.afterJob` is tested here against Job.DEPOSIT and Job.MINE, and elsewhere against other members
of the same set: `afterJob` at save.ts:3:10 (with Job.MOVE, Job.IGNITE and Job.STAFF, without
Job.MINE). One set written out by hand in 2 places, and the copies differ: a member added to one
is missing from the others

✅ Accepted: one set, exported, used by both

✓ Accepted0 diagnostics
ts
export const Job = Object.freeze({ NONE: 0, MOVE: 1, DEPOSIT: 2, IGNITE: 3, STAFF: 4, MINE: 5 });
export type Job = (typeof Job)[keyof typeof Job];

/** Jobs a unit away from them keeps: the checks, the writer and the reader go by this set. */
export const KEPT_JOBS: ReadonlySet<Job> = new Set([Job.MOVE, Job.DEPOSIT, Job.IGNITE, Job.STAFF, Job.MINE]);

type Unit = { readonly afterJob: Job };

export function keptResume(u: Unit): boolean {
  return KEPT_JOBS.has(u.afterJob);
}

export function validAfterJob(afterJob: Job): boolean {
  return KEPT_JOBS.has(afterJob);
}

What counts ​

  • A set: one || (or a range of codes) that tests one value against two members or more: x === A || x === B, (x === A || x === B) && more, x >= A && x <= B over a code object. A single x === A isn't one.
  • The same value: the last name of what is tested (afterJob of u.afterJob, of saved.afterJob and of a local afterJob), with the same closed set (the same code object, or the same union).
  • Reported: each place whose set shares a member with a place in another function. Copies that differ say what each one has that the other doesn't; copies that are the same say where the other copy is.
  • Not reported: tests in one function (the branches of one dispatch), sets that share no member (different questions), and a value tested against sets in more than five functions. That is a value the program dispatches on (u.phase, u.job), whose tests ask many different questions; on an adopter's 35,000-line simulation it cut 91 reports to 18, the real one among them.

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