Skip to content

Commit 7ee4500

Browse files
authored
fix: fixes #1103 by fixing the processing of max-public-structs arguments (#1114)
1 parent cc3ad5f commit 7ee4500

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

rule/max_public_structs.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package rule
22

33
import (
4+
"fmt"
45
"go/ast"
56
"strings"
67
"sync"
@@ -19,7 +20,7 @@ const defaultMaxPublicStructs = 5
1920
func (r *MaxPublicStructsRule) configure(arguments lint.Arguments) {
2021
r.Lock()
2122
defer r.Unlock()
22-
if r.max == 0 {
23+
if r.max != 0 {
2324
return // already configured
2425
}
2526

@@ -43,6 +44,10 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
4344

4445
var failures []lint.Failure
4546

47+
if r.max < 1 {
48+
return failures
49+
}
50+
4651
fileAst := file.AST
4752

4853
walker := &lintMaxPublicStructs{
@@ -56,7 +61,7 @@ func (r *MaxPublicStructsRule) Apply(file *lint.File, arguments lint.Arguments)
5661

5762
if walker.current > r.max {
5863
walker.onFailure(lint.Failure{
59-
Failure: "you have exceeded the maximum number of public struct declarations",
64+
Failure: fmt.Sprintf("you have exceeded the maximum number (%d) of public struct declarations", r.max),
6065
Confidence: 1,
6166
Node: fileAst,
6267
Category: "style",

test/max_public_structs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ func TestMaxPublicStructs(t *testing.T) {
1212
Arguments: []any{int64(1)},
1313
})
1414
}
15+
16+
func TestMaxPublicStructsDefaultConfig(t *testing.T) {
17+
testRule(t, "max_public_structs_ok", &rule.MaxPublicStructsRule{}, &lint.RuleConfig{})
18+
}

testdata/max_public_structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package pkg ...
2-
package pkg // MATCH /you have exceeded the maximum number of public struct declarations/
2+
package pkg // MATCH /you have exceeded the maximum number (1) of public struct declarations/
33

44
type Foo struct {
55
}

testdata/max_public_structs_ok.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Package pkg ...
2+
package pkg
3+
4+
type Foo struct {
5+
}
6+
7+
type Bar struct {
8+
}
9+
10+
type Baz struct {
11+
}

0 commit comments

Comments
 (0)