Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused_import when using a constructor defined transitively #5246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -24,6 +24,11 @@
[jszumski](https://github.com/jszumski)
[#5242](https://github.com/realm/SwiftLint/pull/5242)

* Fix false positive in `unused_import` rule when using a constructor
defined in a transitive module.
[jszumski](https://github.com/jszumski)
[#5246](https://github.com/realm/SwiftLint/pull/5246)

## 0.53.0: Laundry List

#### Breaking
Expand Down
Expand Up @@ -177,6 +177,11 @@ private extension SwiftLintFile {
}

appendUsedImports(cursorInfo: cursorInfo, usrFragments: &usrFragments)

// also collect modules from secondary symbol usage if available
for secondaryInfo in cursorInfo.secondarySymbols {
appendUsedImports(cursorInfo: secondaryInfo, usrFragments: &usrFragments)
}
}

return (imports: imports, usrFragments: usrFragments)
Expand Down
6 changes: 6 additions & 0 deletions Source/SwiftLintCore/Extensions/Dictionary+SwiftLint.swift
Expand Up @@ -180,6 +180,12 @@ public struct SourceKittenDictionary {
let array = value["key.inheritedtypes"] as? [SourceKitRepresentable] ?? []
return array.compactMap { ($0 as? [String: String]).flatMap { $0["key.name"] } }
}

public var secondarySymbols: [SourceKittenDictionary] {
let array = value["key.secondary_symbols"] as? [SourceKitRepresentable] ?? []
return array.compactMap { $0 as? [String: SourceKitRepresentable] }
.map(Self.init)
}
}

extension SourceKittenDictionary {
Expand Down