You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fed2eb5
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: pkg/linters/deferinloop/deferinloop.go
+19-12Lines changed: 19 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,11 @@
1
1
// Package deferinloop implements a Go analysis linter that flags defer
2
-
// statements placed directly inside for or range loop bodies. A defer inside
3
-
// a loop does not execute at the end of each iteration — it runs when the
4
-
// enclosing function returns, which can cause resource leaks and unexpected
5
-
// cleanup ordering.
2
+
// statements inside loops where they run when the enclosing function returns,
3
+
// rather than at the end of each iteration.
6
4
package deferinloop
7
5
8
6
import (
9
7
"go/ast"
8
+
"go/types"
10
9
11
10
"golang.org/x/tools/go/analysis"
12
11
"golang.org/x/tools/go/ast/inspector"
@@ -21,7 +20,7 @@ import (
21
20
varpkgLog=logger.New("linters:deferinloop")
22
21
23
22
// Analyzer is the defer-in-loop analysis pass.
24
-
varAnalyzer=analyzerutil.New("deferinloop", "reports defer statements enclosed anywhere within a for or range loop body; a function literal between a defer and an enclosing loop is treated as a new scope boundary, making the defer exempt; test files are not checked", run)
23
+
varAnalyzer=analyzerutil.New("deferinloop", "reports defer statements inside loops where they run when the enclosing function returns rather than at the end of each iteration; range-over-function iterators and function literals form scope boundaries; test files are not checked", run)
0 commit comments