Skip to content

Commit

Permalink
Preserve @_exported import statements in unused_imports (realm#5242)
Browse files Browse the repository at this point in the history
  • Loading branch information
jszumski authored and KS1019 committed Oct 2, 2023
1 parent ae90a99 commit f098dcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

#### Bug Fixes

* None.
* Fix false positive in `unused_import` rule that triggered on
`@_exported` imports which could break downstream modules if removed.
[jszumski](https://github.com/jszumski)
[#5242](https://github.com/realm/SwiftLint/pull/5242)

## 0.53.0: Laundry List

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private extension SwiftLintFile {
func rangedAndSortedUnusedImports(of unusedImports: [String]) -> [(String, NSRange)] {
return unusedImports
.compactMap { module in
match(pattern: "^(@\\w+ +)?import +\(module)\\b.*?\n").first.map { (module, $0.0) }
match(pattern: "^(@(?!_exported)\\w+ +)?import +\(module)\\b.*?\n").first.map { (module, $0.0) }
}
.sorted(by: { $0.1.location < $1.1.location })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct UnusedImportRuleExamples {
Example("""
import UnknownModule
func foo(error: Swift.Error) {}
"""),
Example("""
@_exported import UnknownModule
""")
] + nonTriggeringExamplesVersionAdditions

Expand Down Expand Up @@ -122,7 +125,7 @@ struct UnusedImportRuleExamples {
dispatchMain()
"""),
Example("""
↓@_exported import Foundation
↓@_implementationOnly import Foundation
import Dispatch
dispatchMain()
"""):
Expand Down

0 comments on commit f098dcf

Please sign in to comment.