realm / realm/SwiftLint

Not all transitive references are corrected by require_explicit_imports

Open
#3,209 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

We use require_explicit_imports: true, and have some found some cases where SwiftLint does not add imports for transitively used swift modules. The ones I've seen so far are:

  1. Use of functions defined on extensions, where the module that defines the extension is not directly imported by the module that references the extension
  2. Calling functions that have parameters with default values, and where the function/initializer of the default is defined in a module not directly imported
  3. References to type metadata from modules not directly referenced. For example, one case was self.mapView.rx.willMove, and the module that defines the type of willMove was not being directly imported (it may also be relevant that the type of willMove is a generic and it conformed to a protocol)

In these cases, if the import does exist, the unused_import rule will remove it, which prevents manual fixes.

The main purpose of this issue is to see if these have been discussed, and to see if these implicit references are visible from SourceKit. These cases were identified when switching to dynamic linking, instead of static linking.

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 require_explicit_imports and unused_import rules, then investigate whether SourceKit exposes the transitive references described: extension functions, default-value functions or initializers, and type metadata. Done means documenting the findings and determining how implicit references should be handled without unused_import removing needed imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.