diff --git a/rule/var-naming.go b/rule/var-naming.go index 3c0c19c..fa4a188 100644 --- a/rule/var-naming.go +++ b/rule/var-naming.go @@ -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) diff --git a/testdata/golint/pkg-caps.go b/testdata/golint/pkg-caps.go new file mode 100644 index 0000000..e8ca0b7 --- /dev/null +++ b/testdata/golint/pkg-caps.go @@ -0,0 +1,4 @@ +// MixedCaps package name + +// Package PkgName ... +package PkgName // MATCH /don't use MixedCaps in package name; PkgName should be pkgname/