Skip to content

Commit ba8672b

Browse files
adonovangopherbot
authored andcommitted
go/analysis/passes/unusedresult: add functions from slices package
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 <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3e8a0a3 commit ba8672b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

go/analysis/passes/unusedresult/unusedresult.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,25 @@ func init() {
5959
// List standard library functions here.
6060
// The context.With{Cancel,Deadline,Timeout} entries are
6161
// effectively redundant wrt the lostcancel analyzer.
62-
funcs.Set("errors.New,fmt.Errorf,fmt.Sprintf,fmt.Sprint,sort.Reverse,context.WithValue,context.WithCancel,context.WithDeadline,context.WithTimeout")
62+
funcs = stringSetFlag{
63+
"context.WithCancel": true,
64+
"context.WithDeadline": true,
65+
"context.WithTimeout": true,
66+
"context.WithValue": true,
67+
"errors.New": true,
68+
"fmt.Errorf": true,
69+
"fmt.Sprint": true,
70+
"fmt.Sprintf": true,
71+
"slices.Clip": true,
72+
"slices.Compact": true,
73+
"slices.CompactFunc": true,
74+
"slices.Delete": true,
75+
"slices.DeleteFunc": true,
76+
"slices.Grow": true,
77+
"slices.Insert": true,
78+
"slices.Replace": true,
79+
"sort.Reverse": true,
80+
}
6381
Analyzer.Flags.Var(&funcs, "funcs",
6482
"comma-separated list of functions whose results must be used")
6583

0 commit comments

Comments
 (0)