Skip to main content

SKY-U003 · Dead code

Unused variable

No severity

Unused-code findings carry no severity in JSON. The terminal report shows them as LOW, SARIF as level note and GitLab as minor. A confidence score from 0 to 100 decides whether they are listed (60 or more by default): 100 for a local variable, at most 90 for a public module-level name and 80 for a class attribute.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

shop/pricing.py · PythonReported on line 8
"""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

shop/receipts.py · Python
"""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

src/http.ts · TypeScriptReported on line 1
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();}
src/main.ts · TypeScript
import { fetchJson } from "./http"; fetchJson("/api/orders").then(console.log);

Not flagged

src/http.ts · TypeScript
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();}

src/main.ts: same as in the flagged example.

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

  1. 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, let and var declarations count (a top-level arrow function counts as a function); PHP properties, C# fields, Dart variables and Swift private properties are read too.
  2. Never reports _, or a local variable of a function that calls locals(), vars() with no argument, eval, exec or reads its own frame.
  3. 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 ExampleSchema can 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.
  4. 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__.py without __all__, as exported.
  5. Skips test, example and benchmark paths and lines marked # noqa: F841 or # 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.

shop/pricing.py · Python · the fix, against the flagged file
"""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 getattr or 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: F841 also works.

    Python
    discounted = subtotal - coupon_amount  # skylos: ignore[SKY-U003] audit log
  • [tool.skylos] ignore = ["SKY-U003"] turns the rule off for the project.

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