Merge pull request #35 from dpetersen/appease-golint

Ensure generated content is friendlier to golint
This commit is contained in:
Mat Ryer 2017-12-06 15:12:51 +00:00 committed by GitHub
commit c80e9a745b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -15,6 +15,49 @@ import (
"text/template" "text/template"
) )
// This list comes from the golint codebase. Golint will complain about any of
// these being mixed-case, like "Id" instead of "ID".
var golintInitialisms = []string{
"ACL",
"API",
"ASCII",
"CPU",
"CSS",
"DNS",
"EOF",
"GUID",
"HTML",
"HTTP",
"HTTPS",
"ID",
"IP",
"JSON",
"LHS",
"QPS",
"RAM",
"RHS",
"RPC",
"SLA",
"SMTP",
"SQL",
"SSH",
"TCP",
"TLS",
"TTL",
"UDP",
"UI",
"UID",
"UUID",
"URI",
"URL",
"UTF8",
"VM",
"XML",
"XMPP",
"XSRF",
"XSS",
}
// Mocker can generate mock structs. // Mocker can generate mock structs.
type Mocker struct { type Mocker struct {
src string src string
@ -240,6 +283,11 @@ var templateFuncs = template.FuncMap{
if s == "" { if s == "" {
return "" return ""
} }
for _, initialism := range golintInitialisms {
if strings.ToUpper(s) == initialism {
return initialism
}
}
return strings.ToUpper(s[0:1]) + s[1:] return strings.ToUpper(s[0:1]) + s[1:]
}, },
} }

View File

@ -33,6 +33,7 @@ func TestMoq(t *testing.T) {
"lockPersonStoreMockGet.Lock()", "lockPersonStoreMockGet.Lock()",
"mock.calls.Get = append(mock.calls.Get, callInfo)", "mock.calls.Get = append(mock.calls.Get, callInfo)",
"lockPersonStoreMockGet.Unlock()", "lockPersonStoreMockGet.Unlock()",
"// ID is the id argument value",
} }
for _, str := range strs { for _, str := range strs {
if !strings.Contains(s, str) { if !strings.Contains(s, str) {