Skip to content

Commit

Permalink
wastedassign: remove limitation related to generics support (golangci…
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonboom authored and SeigeC committed Apr 4, 2023
1 parent 3c06707 commit 4764f8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.38.0").
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/sanposhiho/wastedassign").
WithNoopFallback(m.cfg),
WithURL("https://github.com/sanposhiho/wastedassign"),

linter.NewConfig(golinters.NewWhitespace(whitespaceCfg)).
WithSince("v1.19.0").
Expand Down
8 changes: 7 additions & 1 deletion test/testdata/sqlclosecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var (
)

func rowsCorrectDeferBlock() {

rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -91,6 +90,13 @@ func rowsMissingClose() {
log.Printf("%s are %d years old", strings.Join(names, ", "), age)
}

func rowsMissingCloseG[T ~int64](db *sql.DB, a T) {
rows, _ := db.Query("select id from tb") // want "Rows/Stmt was not closed"
for rows.Next() {
// ...
}
}

func rowsNonDeferClose() {
rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions test/testdata/wastedassign.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ func mugen() {
return
}

func mugenG[T ~int](hoge T) {
var i int
for {
hoge = 5 // want "assigned to hoge, but reassigned without using the value"
// break
}

println(i)
println(hoge)
return
}

func noMugen() {
var i int
var hoge int
Expand Down

0 comments on commit 4764f8d

Please sign in to comment.