lightsoutAlpha

premature-abstraction

an abstraction built before two or three concrete uses called for it

Agent checkadvisory by defaultbasecode

The argument

Premature Abstraction

Wait for 2–3 concrete uses before abstracting. The right abstraction becomes clear with real usage; wrong abstractions are worse than duplication.

The proof

failsrc/forms/renderField.ts
interface Params {
	kind: 'email' | 'phone' | 'address' | 'date';
	label: string;
	value: string;
	required?: boolean;
	hint?: string;
}

// Four shapes and five options, built for one caller. The right abstraction
// shows up after two or three concrete uses; guessed early, it is a shape every
// later use has to be bent to fit.
export const renderField = ({ kind, label, value, required = false, hint }: Params): string => {
	const mark = required ? '*' : '';
	const suffix = hint === undefined ? '' : ` (${hint})`;

	return `<label data-kind="${kind}">${label}${mark}: ${value}${suffix}</label>`;
};
passsrc/forms/renderEmailField.ts
interface Params {
	label: string;
	value: string;
}

// The one case that actually exists, written plainly. When a second and a third
// arrive, what they share will be visible instead of guessed.
export const renderEmailField = ({ label, value }: Params): string => `<label data-kind="email">${label}: ${value}</label>`;

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "premature-abstraction": "advisory" }
"standards-checks": { "premature-abstraction": "off" }