Skip to content

Inconsistent formatting of switch cases with and without content #217

@ainar-g

Description

@ainar-g

Before:

switch x {
case
	longConstantName1,
	longConstantName2:
	// A comment.
	fmt.Println(x)
case
	longConstantName3,
	longConstantName4:
	// Do nothing.
default:
	// Another comment.
	fmt.Println(x * 2)
}

After:

switch x {
case
        longConstantName1,
        longConstantName2:
        // A comment.
        fmt.Println(x)
case longConstantName3, longConstantName4:
        // Do nothing.
default:
        // Another comment.
        fmt.Println(x * 2)
}

Notice how the first case remains multiline (the desired behaviour) while the second case is put onto a single line (not the desired behaviour). The only reason between the two seems to be that the first case has code in it while the second doesn't.

gofumpt --version
v0.3.2-0.20220322194931-6b144e85e83b

Full code: https://go.dev/play/p/cCkatTotVs_L.

I'm ready to provide additional data if that helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions