Skip to content

closure_spacing autocorrect adds a space on every --fix run when closure contains a block comment #6798

Closed

Description

@RobKoch2112

New Issue Checklist

Bug Description

When a closure contains a block comment (/* ... */) and has more than one space before the closing brace, swiftlint --fix adds an additional space on each invocation instead of normalizing to a single space. This creates an infinite spiral — every --fix pass makes the violation worse.

This can happen naturally when swift-format reformats a closure containing a block comment, producing two spaces before }. Once in that state, swiftlint --fix never converges.

import Foundation

func example() {
    let action: () -> Void = { /* no-op */  }
}

Running --fix three times in a row:

$ swiftlint --fix --config .swiftlint.yml Example.swift
Example.swift: Corrected closure_spacing 1 time
# File now contains: { /* no-op */   }  (3 spaces)

$ swiftlint --fix --config .swiftlint.yml Example.swift
Example.swift: Corrected closure_spacing 1 time
# File now contains: { /* no-op */    }  (4 spaces)

$ swiftlint --fix --config .swiftlint.yml Example.swift
Example.swift: Corrected closure_spacing 1 time
# File now contains: { /* no-op */     }  (5 spaces)

Expected: After the first --fix, the spacing should be normalized to { /* no-op */ } (single space on each side). Subsequent runs should produce no changes.

Actual: Each --fix appends one more space before }. The autocorrect reports success on every pass, but the violation is never resolved.

This may be related to the fix in PR #4584 (issues #4565 / #4582), which addressed false-positive detection for block comments in closures. The detection works correctly, but the autocorrect logic appears to unconditionally insert a space rather than replacing the existing whitespace with a single space.

Environment

  • SwiftLint version: 0.65.0 (also reproduced on 0.63.3)
  • Xcode version: Xcode 16.4 (Build version 16F6)
  • Installation method: SPM build tool plugin / Homebrew
  • Configuration file:
opt_in_rules:
  - closure_spacing

Not using nested configurations.

Activity

  1. added
    bug
    on Jul 3, 2026
  2. self-assigned this
    on Jul 3, 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