Skip to content

Fix unused_import for re-exported modules - #6900

Draft
catlover-bot wants to merge 1 commit into
realm:mainfrom
catlover-bot:fix-unused-import-exported-transitive
Draft

Fix unused_import for re-exported modules#6900
catlover-bot wants to merge 1 commit into
realm:mainfrom
catlover-bot:fix-unused-import-exported-transitive

Conversation

@catlover-bot

Copy link
Copy Markdown

Summary

Fix unused_import incorrectly removing an umbrella import when symbols are
used through one of that module's @_exported imports.

SourceKit reports the referenced symbol's defining module, not the umbrella
module imported by the source file. The rule now resolves exported imports
with swift-api-digester before classifying an umbrella import as unused.

Implementation

  • Detect API-digester Import nodes marked Exported.
  • Preserve allowed_transitive_imports and require_explicit_imports.
  • Cache successful lookups by module and compiler context.
  • Retry transient lookup failures.
  • Forward only module-loading compiler arguments and omit plugin paths.
  • Fall back to the previous behavior when the digester cannot run.

Regression coverage

  • Remove the manual Foundation -> CoreFoundation workaround from the
    existing CGFloat example.
  • Test exported versus ordinary imports, argument filtering, cache reuse,
    failure retry, and separate compiler contexts.
  • Verify a real A -> @_exported import B package and a plain-import control.

Validation

  • Resolver unit tests: 4 passed
  • UnusedImportRuleGeneratedTests: passed
  • SwiftPM: 1,091 tests in 375 suites passed
  • SwiftLint self-lint: 0 violations in 713 files
  • Bazel: 19/19 test targets passed
  • Universal release build: passed
  • Exported-import reproduction: 0 violations
  • Plain unused-import control: 1 expected violation

Opened as a draft for cross-platform CI validation of the API-digester
integration.

Closes #5528

@SwiftLintBot

Copy link
Copy Markdown
1 Warning
⚠️ Big PR
20 Messages
📖 Building this branch resulted in a binary size of 28444.16 KiB vs 28415.46 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.68 s vs 0.69 s on main (1% faster).
📖 Linting Alamofire with this PR took 0.97 s vs 0.98 s on main (1% faster).
📖 Linting Brave with this PR took 6.26 s vs 6.26 s on main (0% slower).
📖 Linting Brigade with this PR took 18.12 s vs 18.21 s on main (0% faster).
📖 Linting DuckDuckGo with this PR took 29.99 s vs 29.85 s on main (0% slower).
📖 Linting Firefox with this PR took 11.38 s vs 11.4 s on main (0% faster).
📖 Linting Kickstarter with this PR took 7.32 s vs 7.34 s on main (0% faster).
📖 Linting Moya with this PR took 0.37 s vs 0.37 s on main (0% slower).
📖 Linting NetNewsWire with this PR took 2.49 s vs 2.52 s on main (1% faster).
📖 Linting Nimble with this PR took 0.57 s vs 0.56 s on main (1% slower).
📖 Linting PocketCasts with this PR took 7.38 s vs 7.41 s on main (0% faster).
📖 Linting Quick with this PR took 0.36 s vs 0.36 s on main (0% slower).
📖 Linting Realm with this PR took 2.98 s vs 2.96 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.63 s vs 1.67 s on main (2% faster).
📖 Linting Swift with this PR took 4.54 s vs 4.52 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.18 s vs 0.18 s on main (0% slower).
📖 Linting VLC with this PR took 1.31 s vs 1.3 s on main (0% slower).
📖 Linting Wire with this PR took 16.34 s vs 16.29 s on main (0% slower).
📖 Linting WordPress with this PR took 10.44 s vs 10.51 s on main (0% faster).

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unused_import not taking into account @_exported import

2 participants