[tools] go/analysis/passes/modernize: stditerators: better name heuristic

1 view
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Nov 11, 2025, 12:09:10 PM (yesterday) Nov 11
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Findley, Michael Matloob, Gopher Robot, golang-co...@googlegroups.com

Alan Donovan submitted the change

Unreviewed changes

2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Change information

Commit message:
go/analysis/passes/modernize: stditerators: better name heuristic

This change causes stditerators' name heuristic to choose the
name v from a function body of this form:

for i := 0; i < x.Len(); i++ {
if v := x.At(i); cond { ... }
}

The fix may result in the degenerate

for v := range x.All() {
if v := v; cond { ... }
}

so the forvar analyzer has been taught to recognise this
pattern too (see parent CL).

Updates golang/go#76240
Updates golang/go#76241
Change-Id: I8888fea5adce3e5f55002abadd16527f877e3389
Reviewed-by: Robert Findley <rfin...@google.com>
Files:
  • M go/analysis/passes/modernize/stditerators.go
  • M go/analysis/passes/modernize/testdata/src/stditerators/stditerators.go
  • M go/analysis/passes/modernize/testdata/src/stditerators/stditerators.go.golden
Change size: M
Delta: 3 files changed, 47 insertions(+), 6 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Findley
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I8888fea5adce3e5f55002abadd16527f877e3389
Gerrit-Change-Number: 719361
Gerrit-PatchSet: 4
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Michael Matloob <mat...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages