I ran modernize
on typescript-go
, which caught this code:
if str := strings.TrimPrefix(msg, "Found 'package.json' at '"); str != msg {
// ...
}
And correctly turned it into:
if str, ok := strings.CutPrefix(msg, "Found 'package.json' at '"); ok {
// ...
}
But, right above this code was this:
if str := strings.TrimSuffix(msg, "' does not exist."); str != msg {
// ...
}
That is, the same pattern, but with a suffix. This did not get modernized.
Based on https://github.com/golang/tools/blob/master/gopls/internal/analysis/modernize/stringscutprefix.go (especially its name), it looks as though these modernizations only apply to prefixes, not suffixes. It'd be great to have it in both directions, since the transformation seems about the same?
Comment From: gabyhelp
Related Issues
- x/tools/gopls/internal/analysis/modernize: use strings.Cut #71369
- tools/gopls/internal/analysis/modernize: stringscutprefix offers invalid fix #73547 (closed)
- x/tools/gopls: modernize could suggest using strings.Cut* instead of strings.Split* #74494
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)