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
- Create a simple SwiftUI file with CRLF line endings:
import SwiftUI
struct TestView: View {
var body: some View {
HStack {
VStack {
Text("Hello")
Spacer()
}
}
}
}
-
Convert the file to CRLF line endings (e.g., using unix2dos or saving with Windows line endings)
-
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
Description
The
closure_end_indentationrule corrupts Swift files that have CRLF line endings (\r\n) insteadof Unix LF line endings (
\n).Environment
Steps to Reproduce
Convert the file to CRLF line endings (e.g., using
unix2dosor saving with Windows line endings)Run
swiftlint --fixon the fileExpected Behavior
The file should remain properly formatted, or SwiftLint should report an error about the line
endings.
Actual Behavior
The
closure_end_indentationrule moves closing braces to incorrect positions, corrupting the file:Additional Context
sed -i '' 's/\r$//' file.swift) fixes the issuetrailing_whitespaceandcommawork correctly with CRLF filesWorkaround
Convert files to Unix line endings before running SwiftLint: