Skip to content

Commit

Permalink
Preserve @_exported import statements in unused_imports (#5242)
Browse files Browse the repository at this point in the history
  • Loading branch information
jszumski committed Sep 30, 2023
1 parent d81c2f7 commit 8517e9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
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
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
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 8517e9c

Please sign in to comment.