Skip to content

swiftlint --fix ignores disable:this comment for prefer_key_path rule #6466

Closed

Description

@windaishi

Summary

When running swiftlint --fix, the prefer_key_path rule applies its auto-correction even when the line has an explicit // swiftlint:disable:this prefer_key_path comment. The disable comment should prevent any auto-fix from being applied.

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:
import RxSwift

let observable: Observable<SomeType> = ...

let result = observable
    .map { $0.placeholder } // swiftlint:disable:this prefer_key_path - using a key path here leads to a compilation error
  1. Run swiftlint --fix

Expected Behavior

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

The code should stay as:

.map { $0.placeholder } // swiftlint:disable:this prefer_key_path - using a key path here leads to a compilation error

Actual Behavior

SwiftLint applies the auto-fix despite the disable comment, changing the code to:

.map(\.placeholder) // swiftlint:disable:this prefer_key_path - using a key path here leads to a compilation error

This leaves behind a now-nonsensical disable comment on code that already uses the key path syntax.

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