duplicate-code-block
The same code written out in more than one place.
Deterministic checkAdvises by default
The rule
Agents read this text as written when they write and review code.
When the same code appears in two or more files, such as loading and error handling, validation or a repeated transformation, write it once where file-placement says, and import it.
Copies drift apart, and a fix then reaches only one of them.
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
srcbillinginvoices
interface Params {charges: Array<{ active: boolean; pending: boolean; amount: number; multiplier: number; bonus: number; fee: number; penalty: number }>;}export const totalCharges = ({ charges }: Params): number => {let total = 0;for (const charge of charges) {if (charge.active && charge.amount > 0) {total += charge.amount * charge.multiplier + charge.bonus;} else if (charge.pending) {total += charge.amount / 2 - charge.fee;} else {total -= charge.penalty;}}return total * 100;};
Correct
srcbillinginvoicespipelinerefactor
interface Params {charges: Array<{ amount: number; multiplier: number }>;}export const totalCharges = ({ charges }: Params): number => {return charges.reduce((total, charge) => total + charge.amount * charge.multiplier, 0);};
Configure
- Block
"blocking"Stops a run when a file the run changed breaks the rule. - AdviseDefault
"advisory"Reports it and hands it to the refactor agent. Never stops a run. - 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.
{"standards-rule-settings": {"duplicate-code-block": {"severity": "advisory","options": {"minTokens": 50}}}}