Zum Inhalt springen

Long Method (ARCH3180)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.

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
}
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.