Updated libraries
This commit is contained in:
32
vendor/golang.org/x/lint/lint.go
generated
vendored
32
vendor/golang.org/x/lint/lint.go
generated
vendored
@ -540,6 +540,18 @@ var knownNameExceptions = map[string]bool{
|
||||
"kWh": true,
|
||||
}
|
||||
|
||||
func isInTopLevel(f *ast.File, ident *ast.Ident) bool {
|
||||
path, _ := astutil.PathEnclosingInterval(f, ident.Pos(), ident.End())
|
||||
for _, f := range path {
|
||||
switch f.(type) {
|
||||
case *ast.File, *ast.GenDecl, *ast.ValueSpec, *ast.Ident:
|
||||
continue
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// lintNames examines all names in the file.
|
||||
// It complains if any use underscores or incorrect known initialisms.
|
||||
func (f *file) lintNames() {
|
||||
@ -561,12 +573,22 @@ func (f *file) lintNames() {
|
||||
|
||||
// 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:]
|
||||
f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use leading k in Go names; %s %s should be %s", thing, id.Name, should)
|
||||
if thing == "const" || (thing == "var" && isInTopLevel(f.f, id)) {
|
||||
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:]
|
||||
f.errorf(id, 0.8, link(styleGuideBase+"#mixed-caps"), category("naming"), "don't use leading k in Go names; %s %s should be %s", thing, id.Name, should)
|
||||
}
|
||||
}
|
||||
|
||||
should := lintName(id.Name)
|
||||
|
Reference in New Issue
Block a user