mirror of
https://github.com/mgechev/revive.git
synced 2024-11-21 17:16:40 +02:00
This commit is contained in:
parent
cc3ad5f702
commit
7ee4500e12
@ -1,6 +1,7 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -19,7 +20,7 @@ const defaultMaxPublicStructs = 5
|
||||
func (r *MaxPublicStructsRule) configure(arguments lint.Arguments) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
if r.max == 0 {
|
||||
if r.max != 0 {
|
||||
return // already configured
|
||||
}
|
||||
|
||||
@ -43,6 +44,10 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
|
||||
|
||||
var failures []lint.Failure
|
||||
|
||||
if r.max < 1 {
|
||||
return failures
|
||||
}
|
||||
|
||||
fileAst := file.AST
|
||||
|
||||
walker := &lintMaxPublicStructs{
|
||||
@ -56,7 +61,7 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
|
||||
|
||||
if walker.current > r.max {
|
||||
walker.onFailure(lint.Failure{
|
||||
Failure: "you have exceeded the maximum number of public struct declarations",
|
||||
Failure: fmt.Sprintf("you have exceeded the maximum number (%d) of public struct declarations", r.max),
|
||||
Confidence: 1,
|
||||
Node: fileAst,
|
||||
Category: "style",
|
||||
|
@ -12,3 +12,7 @@ func TestMaxPublicStructs(t *testing.T) {
|
||||
Arguments: []any{int64(1)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestMaxPublicStructsDefaultConfig(t *testing.T) {
|
||||
testRule(t, "max_public_structs_ok", &rule.MaxPublicStructsRule{}, &lint.RuleConfig{})
|
||||
}
|
||||
|
2
testdata/max_public_structs.go
vendored
2
testdata/max_public_structs.go
vendored
@ -1,5 +1,5 @@
|
||||
// Package pkg ...
|
||||
package pkg // MATCH /you have exceeded the maximum number of public struct declarations/
|
||||
package pkg // MATCH /you have exceeded the maximum number (1) of public struct declarations/
|
||||
|
||||
type Foo struct {
|
||||
}
|
||||
|
11
testdata/max_public_structs_ok.go
vendored
Normal file
11
testdata/max_public_structs_ok.go
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// Package pkg ...
|
||||
package pkg
|
||||
|
||||
type Foo struct {
|
||||
}
|
||||
|
||||
type Bar struct {
|
||||
}
|
||||
|
||||
type Baz struct {
|
||||
}
|
Loading…
Reference in New Issue
Block a user