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:
parent
e8d5df7741
commit
d7bedbd946
@ -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
4
testdata/golint/pkg-caps.go
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
// MixedCaps package name
|
||||
|
||||
// Package PkgName ...
|
||||
package PkgName // MATCH /don't use MixedCaps in package name; PkgName should be pkgname/
|
Loading…
x
Reference in New Issue
Block a user