SKY-U002 · Dead code
Unused import
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
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
"""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
"""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()"""Reporting helpers."""from app.reports import render_csvWhy 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
import { readFileSync } from "fs";import path from "path"; export function configPath(name: string): string { return path.join("config", `${name}.json`);}import { configPath } from "./config"; console.log(configPath("app"));Not flagged
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;}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
- Runs on every scan; no flag is needed. Each import binding is a definition: the module name for
import x, the alias forimport x as y, and each name offrom x import a, b. TypeScript and JavaScript named, default and namespace imports, PHPuse, Kotlin and Dart imports are read the same way. - 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.
- Never reports
from __future__imports, and treats imports in a package__init__.pyas exported API: every public name when there is no__all__, otherwise the names__all__lists. - Caps an import inside a
try:whoseexceptcatchesImportErrororModuleNotFoundError(an optional dependency) at confidence 40, below the default threshold of 60, so it is not listed. - Skips imports in test, example and benchmark paths, and imports whose line carries
# noqa: F401, a bare# noqa,# skylos: ignoreor# skylos: ignore[SKY-U002]. Other imports with no reads are listed at confidence 100. - 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
stdtype, 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.
"""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.signalsto register signal handlers, are reported because the bound name is never read. - Re-exports from a module that is not an
__init__.pyare reported unless the module lists them in__all__. - Optional imports inside
try/except ImportErrorare 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: F401also 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.