SKY-UC002 · Dead code
Unreachable statement
A statement in a { ... } block that comes after a return, throw, break or continue in the same block, so it can never run. SKY-UC001 is the Python rule; this one covers the curly-brace languages.
- Languages
- TypeScript, JavaScript, Java, C#, Rust
- Turned on by
skylos . --quality(or-a)- Quality gate
- counted toward the gate limits (full and diff scans). Reported in the quality list, so it counts toward
max_quality(10 by default), notmax_dead_code. - Finding type
- defect
Why it matters
The statement was meant to do something and silently does nothing. Here the rejected coupon is never logged because the call comes after the throw, so support has no record of why a customer's coupon failed.
What Skylos flags
import { CouponExpired } from "./errors";import { logRejectedCoupon } from "./log"; export function applyCoupon(order: Order, coupon: Coupon): void { if (coupon.expired) { throw new CouponExpired(coupon.code); logRejectedCoupon(order, coupon); } order.discount = coupon.amount;}What Skylos leaves alone
export function applyCoupon(order: Order, coupon: Coupon): void { switch (coupon.kind) { case "percent": order.discount = order.total * coupon.rate; break; case "fixed": order.discount = coupon.amount; break; }}Why Skylos leaves it alone
The statement after the first break starts the next case, which a jump can reach. Skylos only looks inside { ... } blocks, and case clauses are not blocks.
More languages
Java
Flagged
package com.shop; public class Coupons { public void applyCoupon(Order order, Coupon coupon) { if (coupon.isExpired()) { throw new CouponExpiredException(coupon.getCode()); logRejected(order, coupon); } order.setDiscount(coupon.getAmount()); }}Not flagged
package com.shop; public class Coupons { public void applyCoupon(Order order, Coupon coupon) { if (coupon.isExpired()) { logRejected(order, coupon); throw new CouponExpiredException(coupon.getCode()); } order.setDiscount(coupon.getAmount()); }}Why Skylos leaves it alone
The log call comes before the throw, so it runs. (Java's own compiler rejects most code after throw; Skylos reports it before the build does.)
Rust
Flagged
pub fn discounted(total: u32, expired: bool) -> u32 { if expired { return total; record_rejection(total); } total - 5} fn record_rejection(_total: u32) {}[package]name = "shop"version = "0.1.0"edition = "2021"Not flagged
pub fn discounted(total: u32, expired: bool) -> u32 { if expired { record_rejection(total); return total; } total - 5} fn record_rejection(_total: u32) {}Why Skylos leaves it alone
The call runs before the early return.
How Skylos decides
- Runs with
--qualityon TypeScript, JavaScript, Java, C# and Rust files. - In each
{ ... }block, finds areturn,throw,breakorcontinuestatement (in Rustreturn,breakorcontinue) and reports the first statement after it that is not a comment, then moves on to the next block. - Only the block's own statements count: an
ifthat returns in both branches does not make the code after it unreachable, andswitchcases are not blocks. - In Rust, macro calls, items such as nested
fnand attributes are not statements here, and a file that does not parse is skipped. - Reports MEDIUM on the line of the unreachable statement.
How to fix it
Move the statement before the jump, or delete it if it is no longer needed.
import { CouponExpired } from "./errors";import { logRejectedCoupon } from "./log"; export function applyCoupon(order: Order, coupon: Coupon): void { if (coupon.expired) {Removed: throw new CouponExpired(coupon.code); logRejectedCoupon(order, coupon);Added: throw new CouponExpired(coupon.code); } order.discount = coupon.amount;}When it can be wrong
- In TypeScript and JavaScript, a helper
functiondeclared after thereturnis reported, although function declarations are hoisted and can be called from above. - It misses code after a call that never returns, such as
process.exit(), and code after anif/elsewhose branches both return.
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
Put the marker on the unreachable line.
TypeScript logRejectedCoupon(order, coupon); // skylos: ignore[SKY-UC002] kept for #77[tool.skylos] ignore = ["SKY-UC002"]turns the rule off for the project.