nicklockwood / SwiftFormat

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

`enumNamespaces` applies even to types with macros attached #1635

Closed jshier closed 5 months ago

jshier commented 7 months ago

Lately, enumNamespaces has started treating simple struct declarations which have parts of their body synthesized by a macro as if they're namespaces. For example, this small, typical example from the Composable Architecture:

@Reducer
struct SummaryScreen {
    @ObservableState
    struct State: Equatable {
        let output: NewExpenseFlowOutput
        var isSubmittingExpense: Bool
    }
    enum Action: Equatable {
        case submitExpense
    }
    // Parent handles action.
}

This currently gets replaced by an enum. I'm not sure how, exactly, the heuristic can be updated to fix this. Perhaps just have the rule ignore types with macros or other attributes attached?

nicklockwood commented 7 months ago

@jshier fixed in 0.53.3

jshier commented 7 months ago

This doesn't appear fixed in 0.53.3. Perhaps the fact my type is more nested is the issue?

@Reducer
struct NewExpenseFeature: Reducer {
    @Reducer(state: .equatable, action: .equatable)
    enum Path {
        case summary(SummaryScreen)

        @Reducer
        struct SummaryScreen {
            @ObservableState
            struct State: Equatable {
                let output: NewExpenseFlowOutput
                var isSubmittingExpense: Bool
            }

            enum Action: Equatable {
                case submitExpense
            }

            // Parent handles action.
        }
    }
}

In that example SummaryScreen still gets converted to an enum.

nicklockwood commented 7 months ago

@jshier it turns out I just messed up and only tested the new logic with classes, not structs 🤦‍♂️

nicklockwood commented 6 months ago

@jshier fixed in 0.53.4

weakfl commented 5 months ago

@nicklockwood I'm still experiencing this issue using version 0.53.7 with macros with a generic argument clause, eg:

@FooMacro<Int>
struct Bar {}

This still gets converted to:

@FooMacro<Int>
enum Bar {}
nicklockwood commented 5 months ago

@nicklockwood I'm still experiencing this issue using version 0.53.7 with macros with a generic argument clause, eg:

I didn't actually realize macros could have generic arguments 😅 I'll get this fixed - thanks

nicklockwood commented 5 months ago

@weakfl fixed in 0.53.8

weakfl commented 5 months ago

Thanks @nicklockwood, works as expected