Skip to content

Commit

Permalink
Fix false positives in unused_import rule for constructors defined …
Browse files Browse the repository at this point in the history
…in transitive modules (#5246)
  • Loading branch information
jszumski committed Oct 1, 2023
1 parent 68b27d8 commit 696e19d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit 696e19d

Please sign in to comment.