Skip to content

Commit ff50ae4

Browse files
authored
wastedassign: remove limitation related to generics support (#3689)
1 parent 09f9e77 commit ff50ae4

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

pkg/lint/lintersdb/manager.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
851851
WithSince("v1.38.0").
852852
WithPresets(linter.PresetStyle).
853853
WithLoadForGoAnalysis().
854-
WithURL("https://github.com/sanposhiho/wastedassign").
855-
WithNoopFallback(m.cfg),
854+
WithURL("https://github.com/sanposhiho/wastedassign"),
856855

857856
linter.NewConfig(golinters.NewWhitespace(whitespaceCfg)).
858857
WithSince("v1.19.0").

test/testdata/sqlclosecheck.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var (
1616
)
1717

1818
func rowsCorrectDeferBlock() {
19-
2019
rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
2120
if err != nil {
2221
log.Fatal(err)
@@ -91,6 +90,13 @@ func rowsMissingClose() {
9190
log.Printf("%s are %d years old", strings.Join(names, ", "), age)
9291
}
9392

93+
func rowsMissingCloseG[T ~int64](db *sql.DB, a T) {
94+
rows, _ := db.Query("select id from tb") // want "Rows/Stmt was not closed"
95+
for rows.Next() {
96+
// ...
97+
}
98+
}
99+
94100
func rowsNonDeferClose() {
95101
rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
96102
if err != nil {

test/testdata/wastedassign.go

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ func mugen() {
117117
return
118118
}
119119

120+
func mugenG[T ~int](hoge T) {
121+
var i int
122+
for {
123+
hoge = 5 // want "assigned to hoge, but reassigned without using the value"
124+
// break
125+
}
126+
127+
println(i)
128+
println(hoge)
129+
return
130+
}
131+
120132
func noMugen() {
121133
var i int
122134
var hoge int

0 commit comments

Comments
 (0)