gomodifytags
gomodifytags copied to clipboard
Don't double up underscores with -transform=snakecase
It would treat an existing underscore as a "word", so one underscore got transformed in to 3.
I run in to this semi-regularly when I copy something like a database schema to a struct:
type Sequence struct {
sequence_id int64
server_id int32
data_type string
increment_by int64
cache_size int64
}
And this gets transformed to:
type Sequence struct {
sequence_id int64 `db:"sequence___id"`
server_id int32 `db:"server___id"`
data_type string `db:"data___type"`
increment_by int64 `db:"increment___by"`
cache_size int64 `db:"cache___size"`
}
I could fix up the field names first, which needs to be done anyway, or use -transform keep, but this makes it do the right thing with the defaults with a minimal of friction, and I don't expect it to break anything for anyone.