Skip to content

Commit

Permalink
go/analysis/passes/unusedresult: add functions from slices package
Browse files Browse the repository at this point in the history
This change adds to the list various slice-altering functions
whose result it is a mistake to ignore.

Change-Id: I0ecdd55b19760c44120e91b198a7f74b1c460bdc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/554317
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan authored and gopherbot committed Jan 5, 2024
1 parent 3e8a0a3 commit ba8672b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion go/analysis/passes/unusedresult/unusedresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,25 @@ func init() {
// List standard library functions here.
// The context.With{Cancel,Deadline,Timeout} entries are
// effectively redundant wrt the lostcancel analyzer.
funcs.Set("errors.New,fmt.Errorf,fmt.Sprintf,fmt.Sprint,sort.Reverse,context.WithValue,context.WithCancel,context.WithDeadline,context.WithTimeout")
funcs = stringSetFlag{
"context.WithCancel": true,
"context.WithDeadline": true,
"context.WithTimeout": true,
"context.WithValue": true,
"errors.New": true,
"fmt.Errorf": true,
"fmt.Sprint": true,
"fmt.Sprintf": true,
"slices.Clip": true,
"slices.Compact": true,
"slices.CompactFunc": true,
"slices.Delete": true,
"slices.DeleteFunc": true,
"slices.Grow": true,
"slices.Insert": true,
"slices.Replace": true,
"sort.Reverse": true,
}
Analyzer.Flags.Var(&funcs, "funcs",
"comma-separated list of functions whose results must be used")

Expand Down

0 comments on commit ba8672b

Please sign in to comment.