SKY-U003 · Dead code
Unused variable
A variable, constant or attribute that is assigned but never read. In a function it is usually a value someone computed and then forgot to use; at module or class level it is a setting nothing looks at any more.
- Languages
- Python, TypeScript/JavaScript (top-level declarations), PHP (properties), C# (fields), Swift (private properties), Dart
- Quality gate
- counted toward the gate limits (full and diff scans). Counts toward
max_dead_code, which has no limit by default, so it only fails a gate where you set one. - Finding type
- review
Why it matters
A computed value that is never used often means a bug: in the example below the discount is worked out but the customer is still charged the full price. Unused settings also mislead readers into thinking they change something.
What Skylos flags
"""Order pricing for the checkout service.""" VAT_RATE = 0.2 def order_total(items, coupon_amount): subtotal = sum(item["price"] * item["qty"] for item in items) discounted = subtotal - coupon_amount return round(subtotal * (1 + VAT_RATE))What Skylos leaves alone
"""Receipt lines for the checkout service.""" def receipt_line(item): name = item["name"] amount = item["price"] * item["qty"] return "{name}: {amount:.2f}".format(**locals())Why Skylos leaves it alone
name and amount are never named again, but locals() hands every local variable to format. Skylos sees the locals() call and keeps all local variables of that function. It does the same for vars(), eval, exec and frame introspection such as sys._getframe.
More languages
TypeScript
Flagged
const RETRY_LIMIT = 3;const TIMEOUT_MS = 5000; export async function fetchJson(url: string) { const signal = AbortSignal.timeout(TIMEOUT_MS); const response = await fetch(url, { signal }); return response.json();}import { fetchJson } from "./http"; fetchJson("/api/orders").then(console.log);Not flagged
const TIMEOUT_MS = 5000; export async function fetchJson(url: string) { const signal = AbortSignal.timeout(TIMEOUT_MS); const response = await fetch(url, { signal }); return response.json();}Why Skylos leaves it alone
Every top-level constant is read. In TypeScript and JavaScript only top-level declarations are checked; a variable inside a function is not.
How Skylos decides
- Runs on every scan; no flag is needed. In Python every assignment target is a definition: module-level names, class attributes and local variables. In TypeScript and JavaScript only top-level
const,letandvardeclarations count (a top-level arrow function counts as a function); PHP properties, C# fields, Dart variables and Swift private properties are read too. - Never reports
_, or a local variable of a function that callslocals(),vars()with no argument,eval,execor reads its own frame. - Skips fields that a framework reads by declaration, including Enum members, dataclass, attrs and NamedTuple fields, Pydantic and SQLModel fields, mapped SQLAlchemy columns, Django and DRF settings and serializer fields, Marshmallow fields and type aliases. For Pydantic and SQLModel, Skylos follows the model base through imports and aliases. A local base named
ExampleSchemacan still have unused fields. A class attribute whose name also appears as an attribute of another class is kept too, since Skylos cannot tell which class a read belongs to. - Lowers confidence by 40 for an upper-case class attribute such as
MAX_ITEMS, caps a class attribute at 80 and a public module-level name at 90 (it can be imported from outside the project), and treats names in__all__, or public names of an__init__.pywithout__all__, as exported. - Skips test, example and benchmark paths and lines marked
# noqa: F841or# skylos: ignore[SKY-U003], then confirms with a text search of the project (for a Python local, only inside the function that owns it). The rest is listed when it scores at least the threshold (--confidence, default 60).
How to fix it
Use the value or delete the assignment. Here the discount was meant to be charged, so the total must be computed from it.
"""Order pricing for the checkout service.""" VAT_RATE = 0.2 def order_total(items, coupon_amount): subtotal = sum(item["price"] * item["qty"] for item in items) discounted = subtotal - coupon_amountRemoved: return round(subtotal * (1 + VAT_RATE))Added: return round(discounted * (1 + VAT_RATE))When it can be wrong
- Module-level settings read by a framework through
getattror a settings loader can be reported when the framework is not one Skylos knows. - Class attributes read only through
self.__dict__or serialisation libraries Skylos does not know are reported. - Unused variables inside TypeScript and JavaScript functions are not checked at all.
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 assignment line, with a reason.
# noqa: F841also works.Python discounted = subtotal - coupon_amount # skylos: ignore[SKY-U003] audit log[tool.skylos] ignore = ["SKY-U003"]turns the rule off for the project.