`unused_import` not taking into account `@_exported import`
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
I'm running into the exact same as #2877. I see there were a few improvements to this in 0.54, but with a multi-module setup like in #2877, import A is removed when the code depends on symbols from B. Similarly, code that depends on CoreFoundation (for example, CGFloat), but only imports Foundation gets this import removed.
Complete output when running SwiftLint, including the stack trace and command used
I haven't tried a small repro project, and this is currently happening in a large project so the output is very long. This is the command:
$ xcodebuild -configuration Debug -workspace ${WORKSPACE} -scheme ${SCHEME} -destination 'generic/platform=iOS' | tee build.log
$ swiftlint analyze --compiler-log-path build.log --fix
Environment
- SwiftLint version: 0.54.0
- Installation method used: from GitHub release (since 0.54 is not available on Homebrew)
- Paste your configuration file:
analyzer_rules:
- unused_import
- Are you using nested configurations?
No - Which Xcode version are you using:
Xcode 15.2
Build version 15C500b
- Do you have a sample that shows the issue?
// This is removed
import Foundation
public func method(_ value: CGFloat) {}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the unused_import analyzer rule and reproduce the reported sample using swiftlint analyze --compiler-log-path build.log --fix. Investigate how compiler-log information is used for @_exported import, multi-module dependencies, and Foundation/CoreFoundation symbols; done means required imports are no longer removed while genuinely unused imports remain removable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100