Skip to content

Fix indentation of multiline raw string literals with --indent-strings#2484

Merged
calda merged 2 commits intodevelopfrom
copilot/fix-indentation-multiline-strings
Mar 30, 2026
Merged

Fix indentation of multiline raw string literals with --indent-strings#2484
calda merged 2 commits intodevelopfrom
copilot/fix-indentation-multiline-strings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

The indentStrings option was silently ignored for raw multiline string literals (#"""..."""#, ##"""..."""##), always stripping their content indentation regardless of the setting.

Root cause: The indentStrings post-processing block matched only .startOfScope("\"\"\"") — the exact plain-""" token — missing raw variants like #""", ##""", etc.

Fix:

  • Replace forEach(.startOfScope("\"\"\"")) with forEachToken(where:) matching any multiline string start-of-scope that contains " — this covers all hash-prefixed string delimiters while correctly excluding multiline regex literals (#/.../#, which also satisfy isMultilineStringDelimiter)
- formatter.forEach(.startOfScope("\"\"\"")) { stringStartIndex, _ in
+ formatter.forEachToken(where: {
+     // Match multiline string literals (""", #""", ##""", etc.) but not multiline regex literals (#/.../#)
+     $0.isStartOfScope && $0.isMultilineStringDelimiter && $0.string.contains("\"")
+ }) { stringStartIndex, _ in

Tests added (mirroring existing indentStrings coverage for non-raw strings):

  • indentStrings: true inside a method with #"""
  • No-extra-indent when #""" is on its own line (omitted return)
  • Top-level indent/unindent with #"""
  • Double-hash delimiter ##"""..."""##

Copilot AI changed the title [WIP] Fix indentation issue for multiline strings with hash marks Fix indentation of multiline raw string literals with --indent-strings Mar 30, 2026
Copilot AI requested a review from calda March 30, 2026 21:15
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (36c910a) to head (df3fea4).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2484      +/-   ##
===========================================
- Coverage    95.30%   95.29%   -0.01%     
===========================================
  Files          167      167              
  Lines        25346    25349       +3     
===========================================
+ Hits         24156    24157       +1     
- Misses        1190     1192       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@calda calda marked this pull request as ready for review March 30, 2026 21:42
@calda calda merged commit 3a5f598 into develop Mar 30, 2026
21 of 22 checks passed
@calda calda deleted the copilot/fix-indentation-multiline-strings branch March 30, 2026 21:42
calda added a commit that referenced this pull request Apr 11, 2026
…gs` (#2484)

Co-authored-by: calda <1811727+calda@users.noreply.github.com>
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.

Indentation of multiline strings wrapped by hash marks is not respected

2 participants