lightsoutAlpha

class-inheritance

Sharing behaviour between classes.

Deterministic checkAgent checkAdvises by default

The rule

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

Never share behaviour through extends. Share by composition: hold the common part as a value the composer creates and passes in, and delegate to it. State contracts as interfaces; implements is not inheritance.

  • Error is the one base you may extend, including an error family such as extends HttpError, because subclassing is the only way to make a typed error that instanceof can check.
  • When a framework's contract is a base class, extending it is allowed. Treat a decorated class as framework-owned.

A base class couples every subclass to its internals: a change or an override acts at a distance, and what is shared hides in a second file.

Examples

The check flags the incorrect code and passes the correct code; the agent judges what the check cannot see. 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

srcruns
src/runs/RefactorRun.ts
class RunState {
protected steps: string[] = [];
record({ step }: { step: string }): void {
this.steps.push(step);
}
}
export class RefactorRun extends RunState {
decline({ step }: { step: string }): void {
this.record({ step: `declined:${step}` });
}
}

Correct

srcruns
src/runs/RefactorRun.ts
interface RunRecorder {
record: (params: { step: string }) => void;
}
const createRunRecorder = (): RunRecorder => {
const steps: string[] = [];
return { record: ({ step }) => steps.push(step) };
};
// The shared part is held as a value and delegated to — visible at the seam.
export class RefactorRun implements RunRecorder {
private readonly recorder = createRunRecorder();
record({ step }: { step: string }): void {
this.recorder.record({ step });
}
decline({ step }: { step: string }): void {
this.recorder.record({ step: `declined:${step}` });
}
}

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": {
"class-inheritance": "advisory"
}
}

Packs that select it