Skip to content

Commit 3df32d1

Browse files
authored
fix: funlen ignore-comments (#5594)
1 parent 988b38e commit 3df32d1

11 files changed

+482
-57
lines changed

.golangci.next.reference.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ linters:
544544
# Default: 40
545545
statements: -1
546546
# Ignore comments when counting lines.
547-
# Default false
548-
ignore-comments: true
547+
# Default: true
548+
ignore-comments: false
549549

550550
ginkgolinter:
551551
# Suppress the wrong length assertion warning.

jsonschema/golangci.jsonschema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@
13191319
"ignore-comments": {
13201320
"description": "Ignore comments when counting lines.",
13211321
"type": "boolean",
1322-
"default": false
1322+
"default": true
13231323
}
13241324
}
13251325
},

jsonschema/golangci.next.jsonschema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@
13191319
"ignore-comments": {
13201320
"description": "Ignore comments when counting lines.",
13211321
"type": "boolean",
1322-
"default": false
1322+
"default": true
13231323
}
13241324
}
13251325
},

pkg/config/linters_settings.go

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var defaultLintersSettings = LintersSettings{
4141
Forbidigo: ForbidigoSettings{
4242
ExcludeGodocExamples: true,
4343
},
44+
Funlen: FunlenSettings{
45+
IgnoreComments: true,
46+
},
4447
GoChecksumType: GoChecksumTypeSettings{
4548
DefaultSignifiesExhaustive: true,
4649
},

pkg/golinters/funlen/funlen.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func New(settings *config.FunlenSettings) *goanalysis.Linter {
1919
if settings != nil {
2020
cfg.lineLimit = settings.Lines
2121
cfg.stmtLimit = settings.Statements
22-
cfg.ignoreComments = !settings.IgnoreComments
22+
cfg.ignoreComments = settings.IgnoreComments
2323
}
2424

2525
a := funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments)
+178-32
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,188 @@
11
//golangcitest:args -Efunlen
2-
//golangcitest:config_path testdata/funlen.yml
32
package testdata
43

5-
func TooManyLines() { // want `Function 'TooManyLines' is too long \(22 > 20\)`
4+
func TooManyLines() { // want `Function 'TooManyLines' is too long \(70 > 60\)`
65
t := struct {
7-
A string
8-
B string
9-
C string
10-
D string
11-
E string
12-
F string
13-
G string
14-
H string
15-
I string
6+
A0 string
7+
A1 string
8+
A2 string
9+
A3 string
10+
A4 string
11+
A5 string
12+
A6 string
13+
A7 string
14+
A8 string
15+
A9 string
16+
A10 string
17+
A11 string
18+
A12 string
19+
A13 string
20+
A14 string
21+
A15 string
22+
A16 string
23+
A17 string
24+
A18 string
25+
A19 string
26+
A20 string
27+
A21 string
28+
A22 string
29+
A23 string
30+
A24 string
31+
A25 string
32+
A26 string
33+
A27 string
34+
A28 string
35+
A29 string
36+
A30 string
37+
A31 string
38+
A32 string
1639
}{
17-
`a`,
18-
`b`,
19-
`c`,
20-
`d`,
21-
`e`,
22-
`f`,
23-
`g`,
24-
`h`,
25-
`i`,
40+
A0: "a",
41+
A1: "a",
42+
A2: "a",
43+
A3: "a",
44+
A4: "a",
45+
A5: "a",
46+
A6: "a",
47+
A7: "a",
48+
A8: "a",
49+
A9: "a",
50+
A10: "a",
51+
A11: "a",
52+
A12: "a",
53+
A13: "a",
54+
A14: "a",
55+
A15: "a",
56+
A16: "a",
57+
A17: "a",
58+
A18: "a",
59+
A19: "a",
60+
A20: "a",
61+
A21: "a",
62+
A22: "a",
63+
A23: "a",
64+
A24: "a",
65+
A25: "a",
66+
A26: "a",
67+
A27: "a",
68+
A28: "a",
69+
A29: "a",
70+
A30: "a",
71+
A31: "a",
72+
A32: "a",
2673
}
2774
_ = t
2875
}
2976

30-
func TooManyStatements() { // want `Function 'TooManyStatements' has too many statements \(11 > 10\)`
31-
a := 1
32-
b := a
33-
c := b
34-
d := c
35-
e := d
36-
f := e
37-
g := f
38-
h := g
39-
i := h
40-
j := i
41-
_ = j
77+
func TooManyStatements() { // want `Function 'TooManyStatements' has too many statements \(46 > 40\)`
78+
a0 := 1
79+
a1 := 1
80+
a2 := 1
81+
a3 := 1
82+
a4 := 1
83+
a5 := 1
84+
a6 := 1
85+
a7 := 1
86+
a8 := 1
87+
a9 := 1
88+
a10 := 1
89+
a11 := 1
90+
a12 := 1
91+
a13 := 1
92+
a14 := 1
93+
a15 := 1
94+
a16 := 1
95+
a17 := 1
96+
a18 := 1
97+
a19 := 1
98+
a20 := 1
99+
a21 := 1
100+
a22 := 1
101+
_ = a0
102+
_ = a1
103+
_ = a2
104+
_ = a3
105+
_ = a4
106+
_ = a5
107+
_ = a6
108+
_ = a7
109+
_ = a8
110+
_ = a9
111+
_ = a10
112+
_ = a11
113+
_ = a12
114+
_ = a13
115+
_ = a14
116+
_ = a15
117+
_ = a16
118+
_ = a17
119+
_ = a18
120+
_ = a19
121+
_ = a20
122+
_ = a21
123+
_ = a22
124+
}
125+
126+
func withComments() {
127+
// Comment 1
128+
// Comment 2
129+
// Comment 3
130+
// Comment 4
131+
// Comment 5
132+
// Comment 6
133+
// Comment 7
134+
// Comment 8
135+
// Comment 9
136+
// Comment 10
137+
// Comment 11
138+
// Comment 12
139+
// Comment 13
140+
// Comment 14
141+
// Comment 15
142+
// Comment 16
143+
// Comment 17
144+
// Comment 18
145+
// Comment 19
146+
// Comment 20
147+
// Comment 21
148+
// Comment 22
149+
// Comment 23
150+
// Comment 24
151+
// Comment 25
152+
// Comment 26
153+
// Comment 27
154+
// Comment 28
155+
// Comment 29
156+
// Comment 30
157+
// Comment 31
158+
// Comment 32
159+
// Comment 33
160+
// Comment 34
161+
// Comment 35
162+
// Comment 36
163+
// Comment 37
164+
// Comment 38
165+
// Comment 39
166+
// Comment 40
167+
// Comment 41
168+
// Comment 42
169+
// Comment 43
170+
// Comment 44
171+
// Comment 45
172+
// Comment 46
173+
// Comment 47
174+
// Comment 48
175+
// Comment 49
176+
// Comment 50
177+
// Comment 51
178+
// Comment 52
179+
// Comment 53
180+
// Comment 54
181+
// Comment 55
182+
// Comment 56
183+
// Comment 57
184+
// Comment 58
185+
// Comment 59
186+
// Comment 60
187+
print("Hello, world!")
42188
}

0 commit comments

Comments
 (0)