Skip to main content

SKY-U002 · Dead code

Unused import

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); an import nothing reads starts at 100.

An import that brings a name into a file which the file never uses. The import still runs, loads the module and adds a dependency, but deleting it changes nothing.

Languages
Python, TypeScript/JavaScript, PHP (`use`), Kotlin, Dart, Rust (hidden below the default threshold)
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

Unused imports slow start-up, keep dependencies alive that could be removed, and can create import cycles. They also mislead readers and coding agents about what a module really depends on.

What Skylos flags

app/reports.py · PythonReported on line 4
"""Monthly sales report as CSV."""import csvimport ioimport json  def render_csv(rows):    buffer = io.StringIO()    writer = csv.writer(buffer)    for row in rows:        writer.writerow([row["month"], row["total"]])    return buffer.getvalue()

What Skylos leaves alone

app/reports.py · Python
"""Monthly sales report as CSV."""import csvimport io  def render_csv(rows):    buffer = io.StringIO()    writer = csv.writer(buffer)    for row in rows:        writer.writerow([row["month"], row["total"]])    return buffer.getvalue()
app/__init__.py · Python
"""Reporting helpers."""from app.reports import render_csv

Why Skylos leaves it alone

render_csv is imported in a package's __init__.py that has no __all__. Skylos treats public names there as the package's API (callers write from app import render_csv), so the import is not reported even though nothing in the project uses it.

More languages

TypeScript

Flagged

src/config.ts · TypeScriptReported on line 1
import { readFileSync } from "fs";import path from "path"; export function configPath(name: string): string {  return path.join("config", `${name}.json`);}
src/main.ts · TypeScript
import { configPath } from "./config"; console.log(configPath("app"));

Not flagged

src/config.ts · TypeScript
import type { Stats } from "fs";import path from "path"; export function configPath(name: string): string {  return path.join("config", `${name}.json`);} export function isLarge(stats: Stats): boolean {  return stats.size > 1_000_000;}
src/main.ts · TypeScript
import { configPath, isLarge } from "./config"; console.log(configPath("app"), isLarge);

Why Skylos leaves it alone

Stats is only used as a type annotation. A type-only use still counts as a use, so the import is kept.

How Skylos decides

  1. Runs on every scan; no flag is needed. Each import binding is a definition: the module name for import x, the alias for import x as y, and each name of from x import a, b. TypeScript and JavaScript named, default and namespace imports, PHP use, Kotlin and Dart imports are read the same way.
  2. Counts a binding as used when the file reads the name anywhere, including in type annotations. In TypeScript, only a use in the same file counts: the same word in another file never keeps an import alive.
  3. Never reports from __future__ imports, and treats imports in a package __init__.py as exported API: every public name when there is no __all__, otherwise the names __all__ lists.
  4. Caps an import inside a try: whose except catches ImportError or ModuleNotFoundError (an optional dependency) at confidence 40, below the default threshold of 60, so it is not listed.
  5. Skips imports in test, example and benchmark paths, and imports whose line carries # noqa: F401, a bare # noqa, # skylos: ignore or # skylos: ignore[SKY-U002]. Other imports with no reads are listed at confidence 100.
  6. In Rust, a trait import is used by method calls that never name it, so an unread import is reported only when it cannot be such a trait: a module, function or constant, a project item that is not a trait, an enum variant, a known non-trait std type, a trait the edition's prelude already imports, or a trait none of whose members its scope reaches. Other imports are abstentions. use Trait as _ is never reported, nor is an import under #[allow(unused_imports)].

How to fix it

Delete the import. If it is there for a side effect (registering a plugin, patching a library), say so on the line with an inline suppression instead, so the next reader does not delete it.

app/reports.py · Python · the fix, against the flagged file
"""Monthly sales report as CSV."""import csvimport ioRemoved: import json  def render_csv(rows):    buffer = io.StringIO()    writer = csv.writer(buffer)    for row in rows:        writer.writerow([row["month"], row["total"]])    return buffer.getvalue()

When it can be wrong

  • Imports kept for their side effect, such as import app.signals to register signal handlers, are reported because the bound name is never read.
  • Re-exports from a module that is not an __init__.py are reported unless the module lists them in __all__.
  • Optional imports inside try/except ImportError are held back even when they are really unused.

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 import line, with a reason. # noqa: F401 also works, since it is the code Ruff and flake8 use for the same problem.

    Python
    import json  # skylos: ignore[SKY-U002] imported for its side effect
  • [tool.skylos] ignore = ["SKY-U002"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the unused imports you already have.

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