Fix multiline string literal handling with partial selections and whitespace-only linting. #1335
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 393 lines diff across 4 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.358
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1335"
general
weight: 0.35
dylansturg
Summary
This PR fixes two bugs in how
swift-formathandles multiline string literals ("""...""") when formatting or linting line ranges (--lines) or runningWhitespaceLinter:1. Preserve multiline string literals that are only partially selected
When formatting or linting a line range (
--lines) that overlaps only part of a multiline string literal,TokenStreamCreatorpreviously only checked selection boundaries invisit(_ token: TokenSyntax), which is invoked foropeningQuoteandclosingQuotewhileStringSegmentSyntaxandExpressionSegmentSyntaxreturn.skipChildren:Because the closing
"""token on line 4 enteredvisit(_ token:)while lines 2–3 were outside the selection, the pretty printer re-indented only the closing delimiter to 2 spaces while leaving the segment lines at 4 spaces, silently changing the runtimeStringvalue. Conversely, a selection starting on the opening"""and ending mid-string remained enabled through the rest of the literal because segments never calledgenerateDisableFormattingIfNecessary.To avoid changing a multiline string literal's content when its closing quote indentation and segment lines are not formatted together, this change treats multiline
StringLiteralExprSyntaxnodes as atomic for selection formatting and linting: if a multiline string literal is not completely contained within a single selection range (fromopeningQuotethroughclosingQuote), formatting stays disabled across the entire literal and its segments so partially selected multiline strings are left untouched.2. Avoid emitting or stripping multiline string backslash continuations in whitespace-only mode
When
reflowMultilineStringLiteralsis.onlyLinesOverLengthor.always,TokenStreamCreatorsplits multiline string segments into word tokens separated by.break(..., newlines: .escaped)tokens (which print\inPrettyPrinter) and strips existing\line continuations under.always.During
swift-format lint,PrettyPrinterruns withwhitespaceOnly: trueandWhitespaceLinterasserts that all non-whitespace UTF-8 code units in the formatted output match the original source text. Inserting or removing\line-continuation characters or wrapping string segments via.escapedbreaks inwhitespaceOnlymode desynchronizesWhitespaceLinter(triggering the"Non-whitespace characters do not match"assertion in debug builds or emitting misaligned whitespace findings).This change forces
configuration.reflowMultilineStringLiterals = .neverinsidePrettyPrinterwhenwhitespaceOnlyistrue, and guards\emission on.escapedbreaks with!whitespaceOnly. Because reflowing a multiline string literal requires adding or removing\characters (a non-whitespace edit),WhitespaceLinterleaves segment line wrapping unchanged while continuing to lint indentation and surrounding whitespace.