Long Method (ARCH3180)
Esta página aún no está disponible en tu idioma.
Key typescript.quality.long-method · Severity info · Category quality
Functions whose body exceeds the line threshold do too much at once; they become hard to read, test, and change. Logical steps should be extracted into separate functions.
Incorrect
Section titled “Incorrect”function processOrder(o: Order) { if (!o.items.length) throw new Error("empty"); let total = 0; for (const i of o.items) total += i.price * i.qty; const tax = total * 0.18; const shipping = total > 500 ? 0 : 30; const discount = o.coupon ? total * 0.1 : 0; const grand = total + tax + shipping - discount; saveInvoice(o, grand); sendEmail(o.customer, grand); // ...dozens more lines}Correct
Section titled “Correct”function processOrder(o: Order) { validate(o); const totals = computeTotals(o); saveInvoice(o, totals.grand); sendEmail(o.customer, totals.grand);}Split the method into small, single-responsibility helper functions.