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 (realm#5246)
  • Loading branch information
jszumski authored and KS1019 committed Oct 2, 2023
1 parent be40a5d commit e22cf43
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e22cf43

Please sign in to comment.