Skip to content

x/tools/go/analysis/passes/modernize: stringscut reports false positives #76687

@ldez

Description

@ldez

Version

golang.org/x/tools v0.39.0

What did you do?

I run the stringscut analyzer (though golangci-lint) on the code snippets above.

What did you see happen?

$ golangci-lint run --enable-only modernize
foo.go:29:10: stringscut: strings.IndexByte can be simplified using strings.Cut (modernize)
        if i := strings.IndexByte(s, '='); i > 0 {
                ^
1 issues:
* modernize: 1
$ golangci-lint run --enable-only modernize      
bar.go:21:10: stringscut: strings.Index can be simplified using strings.Cut (modernize)
        if i := strings.Index(a, b); i > 0 {
                ^
1 issues:
* modernize: 1

What did you expect to see?

As you can see in the code snippet, the analyzer suggests something that is not equivalent to the original functions.

## Cut
 abc true
a bc true
abc  true
## Original
=abc  false
a bc true
abc  true
## Modified
 abc true
a bc true
abc  true
## Original

b
## Modified

b
b

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.release-blocker

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions