Skip to content

Long list of switch/case options: Split to block (not each on new line). #159

@guettli

Description

@guettli

Orig:

package main

func main() {
	serverType := "dummy"
	switch serverType {
	case "cpx11", "cx21", "cpx21", "cx31", "cpx31", "cx41", "cpx41", "cx51", "cpx51", "ccx11", "ccx12", "ccx13", "ccx21", "ccx22", "ccx23", "ccx31", "ccx32", "ccx33", "ccx41", "ccx42", "ccx43", "ccx51", "ccx52", "ccx53", "ccx62", "ccx63", "cax11", "cax21", "cax31", "cax41", "cx22", "cx32", "cx42", "cx52":
		return
	default:
		return
	}
}

After golines:

package main

func main() {
	serverType := "dummy"
	switch serverType {
	case "cpx11",
		"cx21",
		"cpx21",
		"cx31",
		"cpx31",
		"cx41",
		"cpx41",
		"cx51",
		"cpx51",
		"ccx11",
		"ccx12",
		"ccx13",
		"ccx21",
		"ccx22",
		"ccx23",
		"ccx31",
		"ccx32",
		"ccx33",
		"ccx41",
		"ccx42",
		"ccx43",
		"ccx51",
		"ccx52",
		"ccx53",
		"ccx62",
		"ccx63",
		"cax11",
		"cax21",
		"cax31",
		"cax41",
		"cx22",
		"cx32",
		"cx42",
		"cx52":
		return
	default:
		return
	}
}

I would prefer something like this:

package main

func main() {
	serverType := "dummy"
	switch serverType {
	case "cpx11", "cx21", "cpx21", "cx31", "cpx31", "cx41", "cpx41", "cx51", "cpx51", "ccx11",
		"ccx12", "ccx13", "ccx21", "ccx22", "ccx23", "ccx31", "ccx32", "ccx33", "ccx41", "ccx42",
		"ccx43", "ccx51", "ccx52", "ccx53", "ccx62", "ccx63", "cax11", "cax21", "cax31", "cax41",
		"cx22", "cx32", "cx42", "cx52":
		return
	default:
		return
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions