Skip to content

swiftlint --fix ignores disable comment for redundant_nil_coalescing #6465

Closed

Description

@windaishi

Summary

When running swiftlint --fix, the redundant_nil_coalescing rule removes both the allegedly redundant ?? nil code AND the associated // swiftlint:disable:this redundant_nil_coalescing comment. This is problematic because:

  1. The disable comment should prevent any auto-fix from being applied
  2. The auto-fix silently removes the developer's explicit disable comment

Environment

  • SwiftLint version: 0.63.2
  • Installation method: mise
  • Xcode version: Xcode 26.2 (Build version 17C52)
  • Swift version: Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
  • macOS version: 26.2

Steps to Reproduce

  1. Create a Swift file with the following content:
let result: SomeType? = try someOptionalOperation().flatMap { value in
    if someCondition {
        return try processValue(value)
    }
    return nil
} ?? nil // swiftlint:disable:this redundant_nil_coalescing - false positive
  1. Run swiftlint --fix

Expected Behavior

The line should remain unchanged because the redundant_nil_coalescing rule is explicitly disabled for this line via the // swiftlint:disable:this redundant_nil_coalescing comment.

The code should stay as:

} ?? nil // swiftlint:disable:this redundant_nil_coalescing - false positive

Actual Behavior

SwiftLint removes both the ?? nil AND the disable comment, changing the code to:

}

This is a double violation:

  1. The auto-fix was applied despite the disable comment
  2. The disable comment itself was removed from the codebase

Activity

  1. added
    bug
    on Jan 31, 2026
  2. self-assigned this
    on Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions