From b2769851ce449563878ae78a635a3e76e7a6dc54 Mon Sep 17 00:00:00 2001 From: Don Petersen Date: Mon, 13 Nov 2017 00:33:12 +0000 Subject: [PATCH] Ensure generated content is friendlier to golint I've stolen the list of "initialisms" from the golint codebase. Normally I might try and figure out some way to bring the list in from the source rather than just copy and paste it, since it may fall out of date in the future. However, if you've ever followed any of the PRs in the golint repository, you'll know any change like that would likely be rejected. Most of this list hasn't changed in the last 4 years, so my feeling is that it won't require many more updates for the life of this project. --- pkg/moq/moq.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ pkg/moq/moq_test.go | 1 + 2 files changed, 49 insertions(+) diff --git a/pkg/moq/moq.go b/pkg/moq/moq.go index f4b43c0..ae37714 100644 --- a/pkg/moq/moq.go +++ b/pkg/moq/moq.go @@ -15,6 +15,49 @@ import ( "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. type Mocker struct { src string @@ -240,6 +283,11 @@ var templateFuncs = template.FuncMap{ if s == "" { return "" } + for _, initialism := range golintInitialisms { + if strings.ToUpper(s) == initialism { + return initialism + } + } return strings.ToUpper(s[0:1]) + s[1:] }, } diff --git a/pkg/moq/moq_test.go b/pkg/moq/moq_test.go index 4cd6fc9..bfa7fe1 100644 --- a/pkg/moq/moq_test.go +++ b/pkg/moq/moq_test.go @@ -31,6 +31,7 @@ func TestMoq(t *testing.T) { "lockPersonStoreMockGet.Lock()", "mock.calls.Get = append(mock.calls.Get, callInfo)", "lockPersonStoreMockGet.Unlock()", + "// ID is the id argument value", } for _, str := range strs { if !strings.Contains(s, str) {