Skip to content

Commit d7bedbd

Browse files
authored
1 parent e8d5df7 commit d7bedbd

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

rule/var-naming.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"fmt"
55
"go/ast"
66
"go/token"
7+
"regexp"
78
"strings"
89
"sync"
910

1011
"github.com/mgechev/revive/lint"
1112
)
1213

14+
var anyCapsRE = regexp.MustCompile(`[A-Z]`)
15+
1316
// VarNamingRule lints given else constructs.
1417
type VarNamingRule struct {
1518
configured bool
@@ -60,6 +63,14 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
6063
Category: "naming",
6164
})
6265
}
66+
if anyCapsRE.MatchString(walker.fileAst.Name.Name) {
67+
walker.onFailure(lint.Failure{
68+
Failure: fmt.Sprintf("don't use MixedCaps in package name; %s should be %s", walker.fileAst.Name.Name, strings.ToLower(walker.fileAst.Name.Name)),
69+
Confidence: 1,
70+
Node: walker.fileAst.Name,
71+
Category: "naming",
72+
})
73+
}
6374

6475
ast.Walk(&walker, fileAst)
6576

testdata/golint/pkg-caps.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// MixedCaps package name
2+
3+
// Package PkgName ...
4+
package PkgName // MATCH /don't use MixedCaps in package name; PkgName should be pkgname/

0 commit comments

Comments
 (0)