Skip to content

trailing_closure autocorrect ignores swiftlint:disable:this #6451

@windaishi

Description

@windaishi

New Issue Checklist

Bug Description

When running swiftlint --fix, the trailing_closure rule ignores // swiftlint:disable:this trailing_closure comments and still "corrects" the code. This produces syntactically invalid Swift code that does not compile.

Complete output when running SwiftLint

$ echo 'let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>(
    configureCell: { _, tableView, indexPath, item in // swiftlint:disable:this trailing_closure - false positive
        return cell
    }
)' | swiftlint --fix --use-stdin

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>            { _, tableView, indexPath, item in // swiftlint:disable:this trailing_closure
        return cell
    }

Before:

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>(
    configureCell: { _, tableView, indexPath, item in // swiftlint:disable:this trailing_closure - false positive
        return cell
    }
)

After:

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>            { _, tableView, indexPath, item in // swiftlint:disable:this trailing_closure
        return cell
    }

Environment

  • SwiftLint version (run swiftlint version to be sure): 0.63.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc): mise
  • Xcode version (run xcodebuild -version to be sure): 16.2
  • Configuration file:
opt_in_rules:
  - trailing_closure

trailing_closure:
  severity: error

Expected behavior

The // swiftlint:disable:this trailing_closure comment should prevent autocorrect from modifying this line. The code should remain unchanged.

Actual behavior

The // swiftlint:disable:this trailing_closure comment is ignored during autocorrect

Metadata

Metadata

Assignees

Labels

bugUnexpected and reproducible misbehavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions