nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.81k stars 633 forks source link

Why struct marked with @resultBuilder replaced by enum #1313

Open Mickael-tinytap opened 1 year ago

Mickael-tinytap commented 1 year ago

Hi,

I noticed that a struct maked with @resultBuilder he is replaced by an enum

From:

    @resultBuilder
    struct TinyAlertBuilder {
        static func buildBlock(_ components: TinyAlertAction...) -> [TinyAlertAction] {
            return components
        }
    }

To:

    @resultBuilder
    enum TinyAlertBuilder {
        static func buildBlock(_ components: TinyAlertAction...) -> [TinyAlertAction] {
            return components
        }
    }

What is the reason? and what is the name of the parameter that responsable to this feature?

nicklockwood commented 1 year ago

This is the enumNamespaces rule: https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#enumNamespaces

nicklockwood commented 1 year ago

I didn't anticipate the rule being applied to resultBuilders, but it seems not to cause any build errors. Happy to consider excluding them if you think there's a good reason to do so?

Mickael-tinytap commented 1 year ago

I don't know, I don't think that there is any different in this case between struct and enum both are values type. But it's can be good to add new parameter for this case maybe? Because struct is most used way to write @resultBuilder