From eaa02a8e71f7446f4aee918e10c47f48a82e1ded Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Fri, 5 Oct 2018 16:27:28 -0400 Subject: [PATCH] Make sure generated identifiers don't ever start with a number. --- pkg/generator/generate.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/generator/generate.go b/pkg/generator/generate.go index 5ca23633..8b015c5c 100644 --- a/pkg/generator/generate.go +++ b/pkg/generator/generate.go @@ -9,6 +9,7 @@ import ( "reflect" "sort" "strings" + "unicode" "github.com/sanity-io/litter" @@ -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 {