# Limits of macro automatic formatting

**URL:** <https://forums.swift.org/t/limits-of-macro-automatic-formatting/80597>\
**Category:** Macros\
**Created:** [June 22, 2025, 3:47pm UTC](https://forums.swift.org/t/limits-of-macro-automatic-formatting/80597 "2025-06-22T15:47:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocoaphony](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cocoaphony/32/3872_2.png) [@cocoaphony](https://forums.swift.org/u/cocoaphony)\
**Post date:** [June 22, 2025, 3:47pm UTC](https://forums.swift.org/t/limits-of-macro-automatic-formatting/80597/1 "2025-06-22T15:47:46Z")

</div>

I'm having trouble determining the rules for macro auto-formatting. I'm not sure what's expected and what's a bug. For example, modifying the stringify macro this way:

```
    return ExprSyntax(
        FunctionCallExprSyntax(
            callee: ClosureExprSyntax {
                """
                    (\(argument),\(literal: argument.description))
                    (\(argument),\(literal: argument.description))
                """
            }
        )

```

(I believe this is what's required to have a macro return multiple statements.)

The result is:

```swift
{
    (a + b, "a + b")
    (a + b,"a + b")
}()

```

Even though the inputs are the same, the trivia is different. Is this expected behavior? (It's making it very hard to write tests. I think I'm just going to turn formatting off.)

EDIT: I did not realize how much pain turning off formatting was going to cause. I assumed that things like `IfConfigClauseListSyntax` using the result builder would automatically insert required newlines; is that still trivia?

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [June 22, 2025, 7:07pm UTC](https://forums.swift.org/t/limits-of-macro-automatic-formatting/80597/2 "2025-06-22T19:07:31Z")

</div>

> [@cocoaphony](#):
>
> (It's making it very hard to write tests. I think I'm just going to turn formatting off.)

I don't have an answer for the formatting, and have experienced this many times myself, but these little formatting quirks (which can change between SwiftSyntax versions) was a major reason we made our [macro testing](https://github.com/pointfreeco/swift-macro-testing/blob/2de00af725ff4c43c9a90d7893835de312653169/Tests/MacroTestingTests/AddCompletionHandlerTests.swift#L55-L56) library. It allows you to just re-record all expansions (instead of copy-pasting or manually updating strings) and then you can manually inspect whether any formatting differences were significant or not.

Not saying that it wouldn't be nice to have these formatting quirks ironed out, but it is one possible workaround.
