all: allow ALL_CAPS names if there's only one letter
This lets a name such as V1_10_5 through without giving the ALL_CAPS error.
Change-Id: I69576d21118f0858e6a30374b8037e28d133833a
Reviewed-on: https://go-review.googlesource.com/c/152979
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/lint.go b/lint.go
index 915fbcb..b424245 100644
--- a/lint.go
+++ b/lint.go
@@ -561,8 +561,16 @@
// Handle two common styles from other languages that don't belong in Go.
if len(id.Name) >= 5 && allCapsRE.MatchString(id.Name) && strings.Contains(id.Name, "_") {
- f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use ALL_CAPS in Go names; use CamelCase")
- return
+ capCount := 0
+ for _, c := range id.Name {
+ if 'A' <= c && c <= 'Z' {
+ capCount++
+ }
+ }
+ if capCount >= 2 {
+ f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use ALL_CAPS in Go names; use CamelCase")
+ return
+ }
}
if len(id.Name) > 2 && id.Name[0] == 'k' && id.Name[1] >= 'A' && id.Name[1] <= 'Z' {
should := string(id.Name[1]+'a'-'A') + id.Name[2:]
diff --git a/testdata/names.go b/testdata/names.go
index 0ec1520..ed7dd41 100644
--- a/testdata/names.go
+++ b/testdata/names.go
@@ -59,8 +59,9 @@
CPP_CONST = 1 // MATCH /ALL_CAPS.*CamelCase/
kLeadingKay = 2 // MATCH /k.*leadingKay/
- HTML = 3 // okay; no underscore
- X509B = 4 // ditto
+ HTML = 3 // okay; no underscore
+ X509B = 4 // ditto
+ V1_10_5 = 5 // okay; fewer than two uppercase letters
)
func f(bad_name int) {} // MATCH /underscore.*func parameter.*bad_name/