wastedassign: remove limitation related to generics support (#3689)

This commit is contained in:
Anton Telyshev 2023-03-13 21:35:21 +02:00 committed by GitHub
parent 09f9e77779
commit ff50ae4f99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -851,8 +851,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithSince("v1.38.0"). WithSince("v1.38.0").
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis(). WithLoadForGoAnalysis().
WithURL("https://github.com/sanposhiho/wastedassign"). WithURL("https://github.com/sanposhiho/wastedassign"),
WithNoopFallback(m.cfg),
linter.NewConfig(golinters.NewWhitespace(whitespaceCfg)). linter.NewConfig(golinters.NewWhitespace(whitespaceCfg)).
WithSince("v1.19.0"). WithSince("v1.19.0").

View File

@ -16,7 +16,6 @@ var (
) )
func rowsCorrectDeferBlock() { func rowsCorrectDeferBlock() {
rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age) rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -91,6 +90,13 @@ func rowsMissingClose() {
log.Printf("%s are %d years old", strings.Join(names, ", "), age) 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() { func rowsNonDeferClose() {
rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age) rows, err := db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)
if err != nil { if err != nil {

View File

@ -117,6 +117,18 @@ func mugen() {
return 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() { func noMugen() {
var i int var i int
var hoge int var hoge int