Unused Import
ID |
swift.unused_import |
Severity |
low |
Remediation Complexity |
auto_fix |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Dead Code |
Language |
Swift |
Tags |
dead-code, imports, unused-code |
Description
Reports an import Foo statement where no symbol from module Foo is
referenced anywhere in the file.
import Foundation // OK — URL used below
import Combine // FLAW — no Combine symbol used
import Dispatch // FLAW — no DispatchQueue / DispatchGroup
let endpoint = URL(string: "https://example.com")
Rationale
Unused imports inflate the module’s compile graph, slow incremental builds, and create misleading dependency footprints. They are frequently leftover from refactors, copy-pasted from other files, or added speculatively during exploration and never cleaned up.
Swift modules re-export their public API by name, and there is no
compile-independent way to attach an identifier back to its origin
module without a full symbol table. This detector applies a pragmatic
heuristic: a fixed table of well-known Apple and standard modules
(Foundation, UIKit, SwiftUI, Combine, Dispatch) is paired
with the most common public symbols from each. An import of one of
those modules is flagged when the file mentions <b>none</b> of the
listed symbols. Imports of other modules are skipped — without
compiler integration we cannot tell which identifier comes from
where, and a wrong report is worse than no report.