Skip to content

x/tools/gopls/internal/analysis/modernize: apply modernizations for TrimPrefix to TrimSuffix too #75205

@jakebailey

Description

@jakebailey

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?

Metadata

Metadata

Assignees

Labels

RefactoringIssues related to refactoring toolsToolProposalIssues describing a requested change to a Go tool or command-line program.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions