Skip to content

closure_end_indentation rule corrupts files with CRLF line endings #6598

@Chometh

Description

@Chometh

Description

The closure_end_indentation rule corrupts Swift files that have CRLF line endings (\r\n) instead
of Unix LF line endings (\n).

Environment

  • SwiftLint version: 0.63.2
  • macOS: Tahoe (Darwin 25.1.0)
  • Installation method: Homebrew

Steps to Reproduce

  1. Create a simple SwiftUI file with CRLF line endings:
import SwiftUI

struct TestView: View {
    var body: some View {
        HStack {
            VStack {
                Text("Hello")
                Spacer()
            }
        }
    }
}
  1. Convert the file to CRLF line endings (e.g., using unix2dos or saving with Windows line endings)

  2. Run swiftlint --fix on the file

Expected Behavior

The file should remain properly formatted, or SwiftLint should report an error about the line
endings.

Actual Behavior

The closure_end_indentation rule moves closing braces to incorrect positions, corrupting the file:

import SwiftUI

struct TestView: View {
    var body: some View {
        HStack {
            VStack {
                Text("Hello")
                Spacer()
}
}
    }
}

Additional Context

  • The issue does not occur with Unix LF line endings
  • Converting the file to LF line endings (sed -i '' 's/\r$//' file.swift) fixes the issue
  • The corruption gets worse with more deeply nested SwiftUI view builders
  • Other rules like trailing_whitespace and comma work correctly with CRLF files

Workaround

Convert files to Unix line endings before running SwiftLint:

sed -i '' 's/\r$//' file.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions