Skip to content

Commit 8c5d8fc

Browse files
authored
fix: flag-parameter rule wrongly detects var definition and points to the function signature (#1213)
1 parent a600be2 commit 8c5d8fc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rule/flag_param.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func (w conditionVisitor) Visit(node ast.Node) ast.Visitor {
6969
return false
7070
}
7171

72+
_, ok = w.idents[ident.Name]
73+
if !ok {
74+
return false
75+
}
76+
7277
return w.idents[ident.Name] == struct{}{}
7378
}
7479

testdata/flag_param.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package fixtures
22

3-
func foo(a bool, b int) { // MATCH /parameter 'a' seems to be a control flag, avoid control coupling/
3+
func fooFlagP(a bool, b int) { // MATCH /parameter 'a' seems to be a control flag, avoid control coupling/
44
if a {
55

66
}
77
}
88

9-
func foo(a bool, b int) {
9+
func barFlagP(a bool, b int) {
1010
str := mystruct{a, b}
1111
}
12+
13+
// issue #1211
14+
func bazFlagP(a int, b bool) {
15+
lBool := true
16+
if lBool {
17+
// do something
18+
}
19+
}

0 commit comments

Comments
 (0)