realm / realm/SwiftLint

`unused_import` not taking into account `@_exported import`

Open
#5,528 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.