Skip to content

Fix closure_end_indentation corrupting CRLF files#6612

Open
HttpGetBinary wants to merge 3 commits intorealm:mainfrom
HttpGetBinary:fix-crlf-closure-indentation
Open

Fix closure_end_indentation corrupting CRLF files#6612
HttpGetBinary wants to merge 3 commits intorealm:mainfrom
HttpGetBinary:fix-crlf-closure-indentation

Conversation

@HttpGetBinary
Copy link
Copy Markdown

@HttpGetBinary HttpGetBinary commented Apr 19, 2026

Fixes #6598

What's wrong

swiftlint --fix on a CRLF file moves closing braces to wrong positions, corrupting it.

Why

Two bugs in ClosureEndIndentationRule:

  1. getFirstNonWhitespaceColumn reads line content including a trailing \r on CRLF files, skewing column distance calculations.
  2. The correction hardcodes "\n" when inserting a newline, breaking files that use "\r\n".

Fix

  1. Strip \r from line content before measuring indentation.
  2. Detect the file's line ending and use it when inserting newlines in corrections.

@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Apr 19, 2026

19 Messages
📖 Building this branch resulted in a binary size of 27621.9 KiB vs 27621.7 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.2 s vs 0.16 s on main (25% slower).
📖 Linting Alamofire with this PR took 0.23 s vs 0.22 s on main (4% slower).
📖 Linting Brave with this PR took 0.87 s vs 0.87 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 3.58 s vs 3.57 s on main (0% slower).
📖 Linting Firefox with this PR took 1.59 s vs 1.59 s on main (0% slower).
📖 Linting Kickstarter with this PR took 1.0 s vs 0.99 s on main (1% slower).
📖 Linting Moya with this PR took 0.15 s vs 0.13 s on main (15% slower).
📖 Linting NetNewsWire with this PR took 0.37 s vs 0.34 s on main (8% slower).
📖 Linting Nimble with this PR took 0.18 s vs 0.16 s on main (12% slower).
📖 Linting PocketCasts with this PR took 6.14 s vs 0.95 s on main (546% slower).
📖 Linting Quick with this PR took 0.17 s vs 0.14 s on main (21% slower).
📖 Linting Realm with this PR took 0.41 s vs 0.41 s on main (0% slower).
📖 Linting Sourcery with this PR took 0.3 s vs 0.31 s on main (3% faster).
📖 Linting Swift with this PR took 0.52 s vs 0.52 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 3.85 s vs 3.87 s on main (0% faster).
📖 Linting VLC with this PR took 0.26 s vs 0.25 s on main (4% slower).
📖 Linting Wire with this PR took 2.07 s vs 2.08 s on main (0% faster).
📖 Linting WordPress with this PR took 1.43 s vs 1.41 s on main (1% slower).

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

closure_end_indentation rule corrupts files with CRLF line endings

2 participants