SKY-Q301 · Quality, structure and performance
Cyclomatic complexity too high
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-adviceor 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
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
"""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
"""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
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
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
- 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. - Python starts at 1 and adds 1 for each
ifandelif,for,async for,whileand conditional expression; 1 for each operand after the first in anand/orchain; 1 perexcepthandler; 1 perforand perifin a comprehension; and 1 permatchcase that can fail, plus 1 per case guard (case _:adds nothing). - TypeScript and JavaScript start at 1 and add 1 for each
if, classicfor,while,caselabel (notdefault),catchand ternary.for…of,for…in,do…while,&&,||and??add nothing. Java adds 1 forif,for, enhancedfor,while,do,catchand ternaries; switch cases and&&/||add nothing. Go adds 1 forif,for, eachswitchandselectstatement, eachcaseanddefault, and each&&or||. - Reports a score above the limit. The limit is
complexityunder[tool.skylos](default 10) for Python, TS/JS and Java; Go always uses 10. - Python skips test code (test folders,
test_*.pyand*_test.pymodules that define tests, files pytest is configured to collect),examplesandbenchmarksfolders, a top-leveldocsfolder and the rootsetup.py. Minified JavaScript is not scanned. - 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.
"""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/eliforswitchdispatch 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:
&&/||/??andfor…ofloops in TS/JS, and switch cases and&&/||in Java. - Go ignores the
complexitysetting 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
defline (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 = 15under[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.