dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.22k stars 377 forks source link

simple: flag uses of strings.CutPrefix/CutSuffix that should use strings.TrimPrefix/TrimSuffix instead #1608

Open cespare opened 2 months ago

cespare commented 2 months ago

Since the introduction of strings.CutPrefix and strings.CutSuffix I've started noticing code that should use strings.TrimPrefix/strings.TrimSuffix instead:

x, _ := strings.CutPrefix(y, "abc")

I just implemented the trivial analyzer for this for our internal lint tool. Might be a nice (tiny) addition to staticcheck.