Skip to content

Commit

Permalink
Make sure generated identifiers don't ever start with a number.
Browse files Browse the repository at this point in the history
  • Loading branch information
atombender committed Oct 5, 2018
1 parent d045e33 commit eaa02a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"sort"
"strings"
"unicode"

"github.com/sanity-io/litter"

Expand Down Expand Up @@ -211,7 +212,11 @@ func (g *Generator) identifierize(s string) string {
for _, part := range splitIdentifierByCaseAndSeparators(s) {
_, _ = sb.WriteString(g.capitalize(part))
}
return sb.String()
ident := sb.String()
if !unicode.IsLetter(rune(ident[0])) {
ident = "A" + ident
}
return ident
}

func (g *Generator) capitalize(s string) string {
Expand Down

0 comments on commit eaa02a8

Please sign in to comment.