1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-01 13:07:44 +02:00

add golint's package name MixedCaps rule as in 83fdc39ff7/lint.go (L561-L563) (#797)

This commit is contained in:
cce 2023-02-27 13:56:30 -05:00 committed by GitHub
parent e8d5df7741
commit d7bedbd946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -4,12 +4,15 @@ import (
"fmt"
"go/ast"
"go/token"
"regexp"
"strings"
"sync"
"github.com/mgechev/revive/lint"
)
var anyCapsRE = regexp.MustCompile(`[A-Z]`)
// VarNamingRule lints given else constructs.
type VarNamingRule struct {
configured bool
@ -60,6 +63,14 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
Category: "naming",
})
}
if anyCapsRE.MatchString(walker.fileAst.Name.Name) {
walker.onFailure(lint.Failure{
Failure: fmt.Sprintf("don't use MixedCaps in package name; %s should be %s", walker.fileAst.Name.Name, strings.ToLower(walker.fileAst.Name.Name)),
Confidence: 1,
Node: walker.fileAst.Name,
Category: "naming",
})
}
ast.Walk(&walker, fileAst)

4
testdata/golint/pkg-caps.go vendored Normal file
View File

@ -0,0 +1,4 @@
// MixedCaps package name
// Package PkgName ...
package PkgName // MATCH /don't use MixedCaps in package name; PkgName should be pkgname/