lightsoutAlpha

single-return

business logic returning from several branches instead of once at the end

Agent checkadvisory by defaultbasecode

The argument

Single Return Point

Business logic uses a single return at the end — one consistent place to find the result, and a shared post-step (a floor, a wrapper, a log) gets written once instead of repeated per branch, where one branch inevitably forgets it. Exception: guard clauses at the top may return early for validation/null checks.

export const calculateShippingCost = ({ weightKg, isExpress, destination }: Params): number => {
	let cost = weightKg * destination.ratePerKg;

	if (isExpress) {
		cost += destination.expressSurcharge;
	}

	// Minimum-charge floor applies to every path — single return writes it once.
	if (cost < destination.minimumCharge) {
		cost = destination.minimumCharge;
	}

	return cost;
};

The proof

failsrc/shipping/calculateShippingCost.ts
interface Params {
	weightKg: number;
	isExpress: boolean;
	destination: { ratePerKg: number; expressSurcharge: number; minimumCharge: number };
}

// A return per branch, so the minimum-charge floor has to be remembered three
// times — and the express branch is where it was forgotten.
export const calculateShippingCost = ({ weightKg, isExpress, destination }: Params): number => {
	if (isExpress) {
		return weightKg * destination.ratePerKg + destination.expressSurcharge;
	}

	if (weightKg * destination.ratePerKg < destination.minimumCharge) {
		return destination.minimumCharge;
	}

	return weightKg * destination.ratePerKg;
};
passsrc/shipping/calculateShippingCost.ts
interface Params {
	weightKg: number;
	isExpress: boolean;
	destination: { ratePerKg: number; expressSurcharge: number; minimumCharge: number };
}

// One exit, so the floor is written once and applies to every path.
export const calculateShippingCost = ({ weightKg, isExpress, destination }: Params): number => {
	let cost = weightKg * destination.ratePerKg;

	if (isExpress) {
		cost += destination.expressSurcharge;
	}

	if (cost < destination.minimumCharge) {
		cost = destination.minimumCharge;
	}

	return cost;
};

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "single-return": "advisory" }
"standards-checks": { "single-return": "off" }