Skip to content

duplicate_imports deletes @testable import X when import X is also present #6922

Open

Description

@ashton-seek

New Issue Checklist

Bug Description

duplicate_imports treats import X and @testable import X as the same import. --fix deletes whichever line comes second. If a test file puts the plain imports first, the @testable line is the one that goes, and anything that needed internal access from that module fails to compile.

import MyModule
@testable import MyModule
$ swiftlint lint --only-rule duplicate_imports Repro.swift
Repro.swift:2:1: warning: Duplicate Imports Violation: Imports should be unique (duplicate_imports)
$ swiftlint lint --only-rule duplicate_imports --fix Repro.swift
 import MyModule
-@testable import MyModule

Put the @testable line first and --fix keeps that one instead. The rule is choosing by position, not by the attribute.

 @testable import MyModule
-import MyModule

Expected: Prefer to keep the @testable line when correcting.

Environment

  • SwiftLint version: 0.65.1 (latest GitHub release)
  • Xcode version: 26.6, Build version 17F113
  • Installation method: Homebrew
  • Configuration file: none. Reproduced with --only-rule duplicate_imports.
# no configuration file

Are you using nested configurations? No.

Activity

  1. added
    bug
    on Sep 27, 2026
  2. added a commit that references this issue on Oct 6, 2026
    3bcdfce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions