Skip to main content

SKY-Q301 · Quality, structure and performance

Cyclomatic complexity too high

Varies

The catalog gives no severity. Python reports WARN (read as MEDIUM) for a score from the threshold up to 14 and HIGH from 15. TypeScript, JavaScript, Java and Go always report MEDIUM.

Cyclomatic complexity counts the separate paths through a function: one, plus one for every if, loop, case, except or extra and/or operand. SKY-Q301 reports a function whose count is above the limit, 10 by default.

Languages
Python, TypeScript, JavaScript, Java, Go
Quality gate
counted toward the gate limits (full and diff scans). Python and JS/TS findings are listed only when SKY-Q306 also reports the same function; that function's metrics then share one entry, led by the most severe, which the gate counts once. Otherwise they are hidden and counted only with --all-advice or when the rule is named in [tool.skylos.gate] rules. Go and Java findings are listed by default.
Finding type
advice
Catalog name
Cyclomatic complexity
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Every path needs its own test. A function with a dozen paths is hard to test fully, and a change to one rule (a new country, a new discount) can break another path nobody re-checked.

What Skylos flags

app/shipping.py · PythonReported on line 8
"""Shipping prices for the checkout service.""" from decimal import Decimal FREE_SHIPPING_MIN = Decimal("75.00")  def shipping_cost(order, customer):    if order.total >= FREE_SHIPPING_MIN and not customer.is_wholesale:        return Decimal("0")    if order.destination.country == "US":        base = Decimal("5.00")    elif order.destination.country in ("CA", "MX"):        base = Decimal("12.00")    elif order.destination.is_eu:        base = Decimal("15.00")    else:        base = Decimal("25.00")    if order.weight_kg > 20:        base += Decimal("10.00")    elif order.weight_kg > 5:        base += Decimal("4.00")    if order.express:        base *= 2    if customer.is_member or customer.has_coupon("SHIPFREE"):        base -= Decimal("5.00")    return max(base, Decimal("0"))

What Skylos leaves alone

app/shipping.py · Python
"""Shipping prices for the checkout service.""" from decimal import Decimal FREE_SHIPPING_MIN = Decimal("75.00")  def shipping_cost(order, customer):    if order.total >= FREE_SHIPPING_MIN and not customer.is_wholesale:        return Decimal("0")    if order.destination.country == "US":        base = Decimal("5.00")    elif order.destination.country in ("CA", "MX"):        base = Decimal("12.00")    elif order.destination.is_eu:        base = Decimal("15.00")    else:        base = Decimal("25.00")    if order.weight_kg > 20:        base += Decimal("10.00")    if order.express:        base *= 2    if customer.is_member or customer.has_coupon("SHIPFREE"):        base -= Decimal("5.00")    return max(base, Decimal("0"))

Why Skylos leaves it alone

Without the second weight tier the score is exactly 10: 1, plus 7 if/elif branches, plus the and and the or. The rule reports only scores above the limit.

More languages

TypeScript

Flagged

src/orders/status.ts · TypeScriptReported on line 3
type Order = { state: string; refunded: boolean }; export function statusLabel(order: Order): string {  switch (order.state) {    case "new":      return "New";    case "paid":      return order.refunded ? "Refunded" : "Paid";    case "packed":      return "Packed";    case "shipped":      return "Shipped";    case "delivered":      return "Delivered";    case "returned":      return "Returned";    case "lost":      return "Lost in transit";    case "cancelled":      return "Cancelled";    case "held":      return "On hold";    default:      return "Unknown";  }}

Not flagged

src/orders/status.ts · TypeScript
type Order = { state: string; refunded: boolean }; const LABELS: Record<string, string> = {  new: "New",  packed: "Packed",  shipped: "Shipped",  delivered: "Delivered",  returned: "Returned",  lost: "Lost in transit",  cancelled: "Cancelled",  held: "On hold",}; export function statusLabel(order: Order): string {  if (order.state === "paid") {    return order.refunded ? "Refunded" : "Paid";  }  return LABELS[order.state] ?? "Unknown";}

Why Skylos leaves it alone

The labels live in a lookup object, so the function has one if and one ternary: a score of 3. In TS/JS the nine case labels of the flagged version (not default) and the ternary make 11.

How Skylos decides

  1. Runs with --quality. Each function and method is scored on its own: nested functions, classes and lambdas inside it are not added to its score.
  2. Python starts at 1 and adds 1 for each if and elif, for, async for, while and conditional expression; 1 for each operand after the first in an and/or chain; 1 per except handler; 1 per for and per if in a comprehension; and 1 per match case that can fail, plus 1 per case guard (case _: adds nothing).
  3. TypeScript and JavaScript start at 1 and add 1 for each if, classic for, while, case label (not default), catch and ternary. for…of, for…in, do…while, &&, || and ?? add nothing. Java adds 1 for if, for, enhanced for, while, do, catch and ternaries; switch cases and &&/|| add nothing. Go adds 1 for if, for, each switch and select statement, each case and default, and each && or ||.
  4. Reports a score above the limit. The limit is complexity under [tool.skylos] (default 10) for Python, TS/JS and Java; Go always uses 10.
  5. Python skips test code (test folders, test_*.py and *_test.py modules that define tests, files pytest is configured to collect), examples and benchmarks folders, a top-level docs folder and the root setup.py. Minified JavaScript is not scanned.
  6. Reports on the def (or function) line. Python severity is WARN below 15 and HIGH from 15; the other languages report MEDIUM.

How to fix it

Move independent decisions out into small helpers or a lookup table, so each function holds one kind of decision.

app/shipping.py · Python · the fix, against the flagged file
"""Shipping prices for the checkout service.""" from decimal import Decimal FREE_SHIPPING_MIN = Decimal("75.00")Added: BASE_RATES = {Added:     "US": Decimal("5.00"),Added:     "CA": Decimal("12.00"),Added:     "MX": Decimal("12.00"),Added: }  Added: def base_rate(destination):Added:     if destination.is_eu:Added:         return Decimal("15.00")Added:     return BASE_RATES.get(destination.country, Decimal("25.00"))Added:  Added:  Added: def weight_surcharge(weight_kg):Added:     if weight_kg > 20:Added:         return Decimal("10.00")Added:     if weight_kg > 5:Added:         return Decimal("4.00")Added:     return Decimal("0")Added:  Added:  def shipping_cost(order, customer):    if order.total >= FREE_SHIPPING_MIN and not customer.is_wholesale:        return Decimal("0")Removed:     if order.destination.country == "US":Removed:         base = Decimal("5.00")Removed:     elif order.destination.country in ("CA", "MX"):Removed:         base = Decimal("12.00")Removed:     elif order.destination.is_eu:Removed:         base = Decimal("15.00")Removed:     else:Removed:         base = Decimal("25.00")Removed:     if order.weight_kg > 20:Removed:         base += Decimal("10.00")Removed:     elif order.weight_kg > 5:Removed:         base += Decimal("4.00")Added:     base = base_rate(order.destination) + weight_surcharge(order.weight_kg)    if order.express:        base *= 2    if customer.is_member or customer.has_coupon("SHIPFREE"):        base -= Decimal("5.00")    return max(base, Decimal("0"))

When it can be wrong

  • A flat if/elif or switch dispatch over many values scores high but reads easily. Cognitive complexity (SKY-Q306) scores it lower, which is why a Python or JS/TS finding stays hidden unless both agree.
  • It misses branching it does not count: &&/||/?? and for…of loops in TS/JS, and switch cases and &&/|| in Java.
  • Go ignores the complexity setting and always uses 10.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • On the def line (the reported line):

    Python
    def shipping_cost(order, customer):  # skylos: ignore[SKY-Q301] pricing table
  • [tool.skylos] ignore = ["SKY-Q301"] turns the rule off for the project; complexity = 15 under [tool.skylos] raises the limit instead. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.