mirror of
https://github.com/mgechev/revive.git
synced 2025-02-03 13:11:25 +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"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/mgechev/revive/lint"
|
"github.com/mgechev/revive/lint"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var anyCapsRE = regexp.MustCompile(`[A-Z]`)
|
||||||
|
|
||||||
// VarNamingRule lints given else constructs.
|
// VarNamingRule lints given else constructs.
|
||||||
type VarNamingRule struct {
|
type VarNamingRule struct {
|
||||||
configured bool
|
configured bool
|
||||||
@ -60,6 +63,14 @@ func (r *VarNamingRule) Apply(file *lint.File, arguments lint.Arguments) []lint.
|
|||||||
Category: "naming",
|
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)
|
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