Fix: ignore comments in unreachable statement check. (#1478)
diff --git a/warn/warn_control_flow.go b/warn/warn_control_flow.go
index 8b244c3..c1be14f 100644
--- a/warn/warn_control_flow.go
+++ b/warn/warn_control_flow.go
@@ -118,6 +118,9 @@
unreachable := false
for _, stmt := range stmts {
if unreachable {
+ if _, ok := stmt.(*build.CommentBlock); ok {
+ continue
+ }
callback(stmt)
return true
}
diff --git a/warn/warn_control_flow_test.go b/warn/warn_control_flow_test.go
index 6560765..d6fcdff 100644
--- a/warn/warn_control_flow_test.go
+++ b/warn/warn_control_flow_test.go
@@ -282,6 +282,13 @@
`:4: The statement is unreachable.`,
}, scopeEverywhere)
+ // unreachable comment is ok
+ checkFindings(t, "unreachable", `
+def foo():
+ fail("die")
+
+ # comment
+`, []string{}, scopeEverywhere)
}
func TestNoEffect(t *testing.T) {