Handle CRLF line endings when formatting and linting selections. #1336
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 291 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.340
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1336"
general
weight: 0.35
dylansturg
Summary
Formatting or linting a line range (
--lines) in a file with CRLF (\r\n) line endings previously stripped leading indentation on the first selected line, leaked formatting onto the line following the selection (converting its terminator to\n), and emitted false[TrailingWhitespace]lint findings:Root Causes
1. In Swift's
Charactergrapheme-cluster model,"\r\n"is a single extended grapheme cluster, so"\r\n".hasSuffix("\n")isfalse. When.enableFormattingcopied the unselected prefix ending in\r\nviaPrettyPrintBuffer.writeVerbatimAfterEnablingFormatting,str.hasSuffix("\n")evaluated tofalse, leavingisAtStartOfLine = falseand suppressing leading indentation on the first selected line.2.
Selection.resolved(with:)computed the end of a selected line asnextLineStart.utf8Offset - 1, which in a CRLF file points between\rand\nrather than before\r\n. Because the last token on the selected line ended before\r, its end position was still<the selection's upper bound, so.disableFormattingdid not fire at the end of the selected line.3.
WhitespaceLintersplits whitespace runs on\n(0x0A) only, leaving\r(0x0D) at the end ofuserRunwhileformattedRunon reformatted lines uses\n, which triggered falseremove trailing whitespacefindings and counted\rtoward line length.Fix
String(str).utf8.last == UInt8(ascii: "\n")andoutput.utf8.last == UInt8(ascii: "\n")inPrettyPrintBuffer.writeVerbatimAfterEnablingFormatting.\r\nline terminator when resolving line ranges inSelection.resolved(with:), accounting for the trailing empty slice inSourceLocationConverter.sourceLineswhen a line range's upper bound is out of bounds.\rwhen computing line lengths inWhitespaceLinterand trim a trailing\rbefore comparing pre-newline whitespace runs incheckForTrailingWhitespaceErrors.