Unused Import

ID

kotlin.unused_import

Severity

low

Remediation Complexity

auto_fix

Remediation Risk

low

Remediation Effort

low

Resource

Code Smell

Language

Kotlin

Tags

imports, unused-code

Description

Reports import statements whose imported simple name (or alias, when import x.Foo as F is used) is never referenced in the rest of the compilation unit. Wildcard imports (import x.*) are skipped because the set of imported names cannot be enumerated without symbol resolution.

Rationale

import java.util.Date            // FLAW — never used
import java.util.UUID            // OK — used below
import java.util.HashMap as HM   // FLAW — alias never used

fun id(): String = UUID.randomUUID().toString()

Stale imports add noise at the top of the file, slow code review, and quietly expand the API surface that the file appears to consume.

Remediation

Delete the unused line. Most IDEs offer an automatic "Optimize Imports" action that removes every unused declaration in one keystroke.

References