[tools] go/analysis/passes/modernize: treat 'i += 1' as 'i++'

1 view
Skip to first unread message

Hongxiang Jiang (Gerrit)

unread,
Dec 26, 2025, 9:42:21 PM (2 days ago) Dec 26
to Matthew “strager” Glazar, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Alan Donovan, Gopher Robot, golang-co...@googlegroups.com

Hongxiang Jiang submitted the change

Change information

Commit message:
go/analysis/passes/modernize: treat 'i += 1' as 'i++'

The rangeint modernize pass converts the first loop but not the second, despite
them being equivalent:

for i := 0; i < 10; i++ {}
for i := 0; i < 10; i += 1 {}

Teach the pass to permit i += 1, increasing the pass's usefulness.

Fixes golang/go#76977
Change-Id: I3e993b7d73c59cef8a3e672ca413bb16be897b1e
Reviewed-by: Hongxiang Jiang <hxj...@golang.org>
Reviewed-by: Alan Donovan <adon...@google.com>
Files:
  • M go/analysis/passes/modernize/rangeint.go
  • M go/analysis/passes/modernize/testdata/src/rangeint/rangeint.go
  • M go/analysis/passes/modernize/testdata/src/rangeint/rangeint.go.golden
Change size: S
Delta: 3 files changed, 41 insertions(+), 3 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Alan Donovan, +1 by Hongxiang Jiang
  • 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: I3e993b7d73c59cef8a3e672ca413bb16be897b1e
Gerrit-Change-Number: 732500
Gerrit-PatchSet: 2
Gerrit-Owner: Matthew “strager” Glazar <str...@traduality.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hongxiang Jiang <hxj...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages