Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit 1dcf01a

Browse files
committed
Allow identifier conditions
1 parent d8f3ec1 commit 1dcf01a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/analyzer/occurrences.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ func (nom namedOccurrenceMap) addFromCondition(stmt *ast.IfStmt) {
193193
nom.addFromIdent(stmt.If, e.X)
194194
}
195195
}
196+
case *ast.Ident:
197+
nom.addFromIdent(stmt.If, v)
196198
case *ast.CallExpr:
197199
for _, a := range v.Args {
198200
switch e := a.(type) {

testdata/testdata.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ func notUsed_CondCallExpr_NotOK() {
4242
}
4343
}
4444

45+
func notUsed_CondIdent_NotOK() {
46+
v := getBool() // want "variable '.+' is only used in the if-statement"
47+
if v {
48+
return
49+
}
50+
}
51+
4552
func notUsed_Body_NotOK() {
4653
v := getValue() // want "variable '.+' is only used in the if-statement"
4754
if true {

0 commit comments

Comments
 (0)