تخطَّ إلى المحتوى

Flow complexity (ARCH3206)

هذا المحتوى غير متوفر بلغتك بعد.

Key typescript.quality.flow-complexity · Severity warning · Category quality

Flags a function whose branches and loops are nested so deeply that a reader has to keep several conditions in mind at once. Each if, loop, catch, switch and ternary costs one plus one per level it is nested at; else and else-if cost one; a run of the same &&, || or ?? costs one; a function calling itself costs one; anonymous callbacks deepen what they hold. A named inner function (a component’s handler, a hook’s callback) is scored on its own, and a condition inside JSX markup costs one, flat. Reported above 15.

export function ship(orders: Order[], retry: boolean) {
for (const order of orders) {
if (order.paid) {
for (const line of order.lines) {
if (line.stock > 0 && line.active) {
try { send(line); }
catch { if (retry) queue(line); else fail(line); }
}
}
}
}
}
export function ship(orders: Order[], retry: boolean) {
for (const order of orders.filter(o => o.paid)) shipLines(order, retry);
}
function shipLines(order: Order, retry: boolean) {
for (const line of order.lines.filter(isShippable)) trySend(line, retry);
}