Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle removing system imports #25

Open
keith opened this issue May 4, 2023 · 0 comments
Open

Handle removing system imports #25

keith opened this issue May 4, 2023 · 0 comments

Comments

@keith
Copy link
Member

keith commented May 4, 2023

Right now only your own imports are correctly handled. System imports bring a new set of issues. Here are a few I hit while working on this:

  • You have to handle @objc (and other attributes) requiring a Foundation import
  • extensions on TimeInterval don't find definition because definition is NSTimeInterval. I think the tool would need to understand apinotes to handle this case.
  • Some things come from places you might not expect, and that can be ok. SwiftLint provides a way to map imports. When we were using that we used this config:
unused_import:
  require_explicit_imports: true
  always_keep_imports:
    - AVFoundation # Never translate to AVFAudio, which is only available in 14.5+
  allowed_transitive_imports:
    - module: AVFoundation
      allowed_transitive_imports:
        - AVFAudio
    - module: Foundation
      allowed_transitive_imports:
        - CoreFoundation
        - Darwin
        - ObjectiveC
    - module: CoreMedia
      allowed_transitive_imports:
        - _SwiftCoreMediaOverlayShims
    - module: GoogleMaps
      allowed_transitive_imports:
        - GoogleMapsBase
    - module: GoogleNavigation
      allowed_transitive_imports:
        - GoogleMaps
    - module: UIKit
      allowed_transitive_imports:
        - CoreFoundation
        - CoreGraphics
        - CoreText
        - Darwin
        - ObjectiveC
        - QuartzCore

But this can depend on how strict you want to be. Besides AVFoundation / AVFAudio which you can only fix if you have a high deployment target.

  • Some things you might want to allow shadowing of, like GoogleMapsBase vs GoogleMaps in the example config above, where that framework is distributed as 3 separate frameworks to avoid GitHub's file size limit, but realistically you likely want users to only ever import GoogleMaps, so I think this being user configurable is required.
  • There are some other cases I haven't debugged enough that cause some issues as well, but this is a sense of the work needed
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

No branches or pull requests

1 participant