1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-21 17:16:40 +02:00

fix: fixes #1103 by fixing the processing of max-public-structs arguments (#1114)

This commit is contained in:
chavacava 2024-11-15 09:43:53 +01:00 committed by GitHub
parent cc3ad5f702
commit 7ee4500e12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 3 deletions

View File

@ -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",

View File

@ -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{})
}

View File

@ -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
View File

@ -0,0 +1,11 @@
// Package pkg ...
package pkg
type Foo struct {
}
type Bar struct {
}
type Baz struct {
}