Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wastedassign: remove limitation related to generics support #3689

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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