lightsoutAlpha

single-use-scalar

Where a value used in only one place is declared.

Deterministic checkAdvises by default

The rule

Agents read this text as written when they write and review code.

Declare a scalar that is read in only one place where it is read, not at module scope: const maxRetries = 10; inside the function, not const MAX_RETRIES = 10; at the top of the module. Hoist it to module scope only when two or more places read it, or when it is a lookup map or structured config.

A value declared beside its only reader is read without a jump to find it.

Examples

The check flags the incorrect code and passes the correct code. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.

Incorrect

srcbilling
src/billing/chargeInvoice.ts
const maxRetries = 10;
// A folded number names a value the same way a bare literal does.
const retryWindowMs = 10 * 60_000;
export const chargeInvoice = ({ attempt, elapsedMs }: { attempt: number; elapsedMs: number }): boolean => attempt < maxRetries && elapsedMs < retryWindowMs;

Correct

srcbillingcommonconstants
src/billing/buildReceipt.ts
// Genuinely computed — it has a moving part (an identifier), so it is not a
// folded number, however many places read it.
const startedAt = Date.now();
// A folded number read in two places has earned its module scope.
const graceWindowMs = 5 * 60_000;
const isWithinGrace = ({ elapsedMs }: { elapsedMs: number }) => elapsedMs < graceWindowMs;
export const buildReceipt = ({ elapsedMs }: { elapsedMs: number }): string =>
`started ${startedAt}, grace ${graceWindowMs}, within: ${isWithinGrace({ elapsedMs })}`;

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"single-use-scalar": "advisory"
}
}

Packs that select it