dmarkham / enumer

A Go tool to auto generate methods for your enums
Other
410 stars 66 forks source link

fix: error tranforming empty name with title-lower #79

Closed jazanne closed 2 months ago

jazanne commented 11 months ago

all of the other transforms work with an empty string, but because title-lower tries to access rune at position 0 it throws an error

//go:generate go run github.com/dmarkham/enumer -type=Pill -transform=title-lower --linecomment
type Pill int

const (
    Placebo Pill = iota //
    Aspirin
    Ibuprofen
    Paracetamol
    Acetaminophen = Paracetamol
)

Error

[Info  - 4:09:00 PM] 2023/08/14 16:09:00 panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*Generator).transformValueNames.func8({0x0?, 0x14000080480?})
    /MYREPO/vendor/github.com/dmarkham/enumer/stringer.go:361 +0x84
main.(*Generator).transformValueNames(0x16f3f72df?, {0x140010bf980, 0x5, 0x1?}, {0x16f3f72fb?, 0x160?})
    /MYREPO/vendor/github.com/dmarkham/enumer/stringer.go:388 +0x444
andig commented 5 months ago

ping @dmarkham lgtm

jazanne commented 3 months ago

@dmarkham any chance to get 👀 on this pr?