From 160b87d2a2c19c649fe01b316c76b39ab2a3c18d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 20:53:48 +0000 Subject: [PATCH 1/2] Initial plan From df3fea48b020178352d0dac203c572f149ec26cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:15:03 +0000 Subject: [PATCH 2/2] Fix indentStrings to also handle raw multiline string literals (#\"\"\", ##\"\"\") Agent-Logs-Url: https://github.com/nicklockwood/SwiftFormat/sessions/b3e76418-d5c0-488a-a363-64893ef5d5d3 Co-authored-by: calda <1811727+calda@users.noreply.github.com> --- Sources/Rules/Indent.swift | 5 +- Tests/Rules/IndentTests.swift | 106 ++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/Sources/Rules/Indent.swift b/Sources/Rules/Indent.swift index 7c93aff67..b0da0c316 100644 --- a/Sources/Rules/Indent.swift +++ b/Sources/Rules/Indent.swift @@ -734,7 +734,10 @@ public extension FormatRule { } if formatter.options.indentStrings { - 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 let baseIndent = formatter.currentIndentForLine(at: stringStartIndex) let expectedIndent = baseIndent + formatter.options.indent diff --git a/Tests/Rules/IndentTests.swift b/Tests/Rules/IndentTests.swift index c3a23a67e..dd016b6d2 100644 --- a/Tests/Rules/IndentTests.swift +++ b/Tests/Rules/IndentTests.swift @@ -3773,6 +3773,112 @@ final class IndentTests: XCTestCase { testFormatting(for: input, output, rule: .indent, options: options) } + func testIndentRawMultilineStringInMethod() { + let input = ##""" + func foo() { + let sql = #""" + SELECT * + FROM authors + WHERE authors.name LIKE '%David%' + """# + } + """## + let output = ##""" + func foo() { + let sql = #""" + SELECT * + FROM authors + WHERE authors.name LIKE '%David%' + """# + } + """## + let options = FormatOptions(indentStrings: true) + testFormatting(for: input, output, rule: .indent, options: options) + } + + func testNoIndentRawMultilineStringWithOmittedReturn() { + let input = ##""" + var string: String { + #""" + SELECT * + FROM authors + WHERE authors.name LIKE '%David%' + """# + } + """## + let options = FormatOptions(indentStrings: true) + testFormatting(for: input, rule: .indent, options: options) + } + + func testIndentRawMultilineStringAtTopLevel() { + let input = ##""" + let sql = #""" + SELECT * + FROM authors, + books + WHERE authors.name LIKE '%David%' + AND pubdate < $1 + """# + """## + let output = ##""" + let sql = #""" + SELECT * + FROM authors, + books + WHERE authors.name LIKE '%David%' + AND pubdate < $1 + """# + """## + let options = FormatOptions(indent: " ", indentStrings: true) + testFormatting(for: input, output, rule: .indent, options: options) + } + + func testUnindentRawMultilineStringAtTopLevel() { + let input = ##""" + let sql = #""" + SELECT * + FROM authors, + books + WHERE authors.name LIKE '%David%' + AND pubdate < $1 + """# + """## + let output = ##""" + let sql = #""" + SELECT * + FROM authors, + books + WHERE authors.name LIKE '%David%' + AND pubdate < $1 + """# + """## + let options = FormatOptions(indent: " ", indentStrings: false) + testFormatting(for: input, output, rule: .indent, options: options) + } + + func testIndentDoubleHashRawMultilineStringInMethod() { + let input = ###""" + func foo() { + let sql = ##""" + SELECT * + FROM authors + WHERE authors.name LIKE '%David%' + """## + } + """### + let output = ###""" + func foo() { + let sql = ##""" + SELECT * + FROM authors + WHERE authors.name LIKE '%David%' + """## + } + """### + let options = FormatOptions(indentStrings: true) + testFormatting(for: input, output, rule: .indent, options: options) + } + func testIndentUnderIndentedMultilineStringPreservesBlankLineIndent() { let input = #""" class Main {