← Back to Pull requests

Apply SyntaxFormatRules consistently across format and lint with selections. #1333

Closed
unknown closed this pull request without merging on Nov 10, 2026 19:27 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 17:29 UTC
Author

Previously, SyntaxFormatRule.visitAny called Context.shouldFormat on every visited syntax node and returned the node unchanged without visiting children whenever node.isInsideSelection failed. Because isInsideSelection requires full containment, partial line or offset selections failed at SourceFileSyntax, causing SwiftFormatter to skip all SyntaxFormatRule passes while SwiftLinter still ran them through LintPipeline and emitted findings.

Update SyntaxFormatRule and LintPipeline to descend into syntax subtrees that overlap or touch the selection (while respecting range-scoped // swift-format-ignore directives) and gate individual rewrites and findings on the specific syntax construct or trivia range being modified:

  • Expression, token, and localized sub-node rules check shouldFormat on the rewritten sub-node (such as the semicolon token, return keyword or Void clause, condition element, declaration modifier/keyword, or bound pattern variable).

  • Statement- and item-level list rules (DoNotUseSemicolons, OneCasePerLine, OneVariableDeclarationPerLine, NoCasesWithOnlyFallthrough, UseEarlyExits, UseWhereClausesInForLoops) check shouldFormat on each affected statement or list item while continuing to recurse into sibling and nested blocks.

  • Trivia-based rules (UseTripleSlashForDocumentationComments, NoEmptyLinesOpeningClosingBraces) check shouldFormat(_:triviaRange:) against the trivia piece range rather than the entire declaration or block.

  • OrderedImports reorders and diagnoses an import span only when all statements in the affected import span are inside the selection, leaving unselected trailing statements intact.

  • After each SyntaxFormatRule that modifies the syntax tree in FormatPipeline, update Context (adjusting resolved selection byte ranges by the tree edit deltas) and pass the transformed source string to PrettyPrinter when needed so subsequent rules and token-stream formatting stay byte-offset synchronized.
  • Diff: 251 lines (+188 / -63) across 3 files Reviewer: dylansturg Review duration: 118m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 251 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.331
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1333"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39% (MEDIUM) · Higher = larger blast radius
    39%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%