Unused Import
All imported modules should be required to make the file compile
- Identifier:
unused_import
- Enabled by default: No
- Supports autocorrection: Yes
- Kind: lint
- Analyzer rule: Yes
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning require_explicit_imports false allowed_transitive_imports [] always_keep_imports []
Non Triggering Examples
import Dispatch // This is used
dispatchMain()
@testable import Dispatch
dispatchMain()
import Foundation
@objc
class A {}
import UnknownModule
func foo(error: Swift.Error) {}
@_exported import UnknownModule
import Foundation
let 👨👩👧👦 = #selector(NSArray.contains(_:))
👨👩👧👦 == 👨👩👧👦
//
// allowed_transitive_imports: [Foundation: ["CoreFoundation"]]
//
import Foundation
enum E {
static let min: CGFloat = 44
}
Triggering Examples
↓import Dispatch
struct A {
static func dispatchMain() {}
}
A.dispatchMain()
↓import Foundation // This is unused
struct A {
static func dispatchMain() {}
}
A.dispatchMain()
↓import Dispatch
↓import Foundation
dispatchMain()
↓import Foundation
// @objc
class A {}
↓import Foundation
import UnknownModule
func foo(error: Swift.Error) {}
↓import Swift
↓import SwiftShims
func foo(error: Swift.Error) {}