mysql icon indicating copy to clipboard operation
mysql copied to clipboard

all: run modernize happy

Open zchee opened this issue 1 month ago โ€ข 4 comments

Description

Run go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./....

Checklist

  • [x] Code compiles correctly
  • [x] Created tests which fail without the change (if possible)
  • [x] All tests passing
  • [x] Extended the README / documentation, if necessary
  • [x] Added myself / the copyright holder to the AUTHORS file

zchee avatar Nov 05 '25 22:11 zchee

Walkthrough

Added a contributor entry to AUTHORS, modernized several index-based for-loops to range-style iteration across tests and one implementation file, and removed per-iteration shadowing used for closure capture in test helpers.

Changes

Cohort / File(s) Summary
Author Attribution
AUTHORS
Added new public author entry: Koichi Shiraishi <zchee.io at gmail.com>, maintaining alphabetical order.
Benchmark Loop Modernization
benchmark_test.go
Replaced index-based loops with range-based iterations across multiple benchmark tests (concurrency loops, insertion loops, table-creation loops).
Test Closure Capture
driver_test.go
Removed per-iteration shadowing (test := test) from loops in runTests and runTestsParallel, altering closure capture semantics; small literal and formatting tweaks elsewhere.
Packet Loop Modernization (breaking)
packets.go
Changed skipPackets(n int) loop from for i := 0; i < n; i++ { ... } to for range n { ... } (note: for range n is invalid Go and will fail to compile).

Sequence Diagram(s)

No sequence diagram โ€” changes are refactorings and small test-behavior adjustments that do not introduce new control-flow components warranting a high-level sequence diagram.

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~45 minutes

  • Review focus:
    • packets.go: the for range n construct is invalid in Go; verify intent and fix to a correct iteration form (e.g., for i := 0; i < n; i++ or for range make([]struct{}, n) if deliberate).
    • driver_test.go: check closure behavior after removal of test := test to ensure no test flakiness from variable capture.
    • benchmark_test.go: ensure loop variable usage inside bodies remains correct after range changes.

Possibly related PRs

  • go-sql-driver/mysql#1695 โ€” Applies similar Go-1.22 modernizations (loop-to-range changes and AUTHORS update) to overlapping files.

Suggested reviewers

  • shogo82148
  • methane

Pre-merge checks and finishing touches

โŒ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check โ“ Inconclusive The title 'all: run modernize happy' is vague and non-descriptive, using colloquial language ('happy') that doesn't convey meaningful information about the changeset. Revise the title to be more descriptive, such as 'all: apply Go modernization refactorings' or 'all: run gopls modernize tool for code updates'.
โœ… Passed checks (1 passed)
Check name Status Explanation
Description check โœ… Passed The description clearly relates to the changeset by explaining the modernize tool execution and the corresponding code transformations reflected in the file summaries.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 7ace06996566878841da1308911cb6bdf660a1d5 and 9a9293818ad41c7bd297dd5444712ac6ca592f64.

๐Ÿ“’ Files selected for processing (4)
  • AUTHORS (1 hunks)
  • benchmark_test.go (5 hunks)
  • driver_test.go (2 hunks)
  • packets.go (1 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (3)
  • AUTHORS
  • benchmark_test.go
  • driver_test.go
๐Ÿงฐ Additional context used
๐Ÿง  Learnings (1)
๐Ÿ““ Common learnings
Learnt from: shogo82148
Repo: go-sql-driver/mysql PR: 1576
File: CHANGELOG.md:1-6
Timestamp: 2024-07-26T20:55:56.049Z
Learning: PRs #1562 and #1570 in the go-sql-driver/mysql repository collectively address the same underlying issue related to fixing a race condition when a context is canceled, as documented in the CHANGELOG.md for version 1.8.1.
๐Ÿ”‡ Additional comments (1)
packets.go (1)

909-915: Range-based loop keeps semantics intact.

for range n still invokes mc.readPacket() exactly n times and exits early on the first read error, matching the previous for i := 0; i < n; i++ behavior even when n <= 0. No issues spotted here.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 05 '25 22:11 coderabbitai[bot]

Coverage Status

coverage: 82.409% (-0.1%) from 82.508% when pulling 9a9293818ad41c7bd297dd5444712ac6ca592f64 on zchee:modernize-2025-11-06 into 76c00e35a8d48f8f70f0e7dffe584692bd3fa612 on go-sql-driver:master.

coveralls avatar Nov 06 '25 11:11 coveralls

I have run modernize on April, but I restored some Go 1.20 compatibility later. I don't remember exact reason, but I needed to compare benchmark with old Go and drivers. (Use same benchmark_test.go for old Go/driver version.)

I don't think 1.20 compatibility is needed anymore. But I will wait merging this until I start v1.10 development. Until then, master branch is for maintain v1.9.

methane avatar Nov 07 '25 11:11 methane

@methane I see maintenance policy. and make sense. Note that modernize parses go.mod verdion and will change behavior, current go-mysql uses 1.22 and I thought this chnage safer.

  • https://github.com/go-sql-driver/mysql/blob/master/go.mod#L3.

So, what do you mean belows comment?

I don't think 1.20 compatibility is needed anymore. But I will wait merging this until I start v1.10 development. Until then, master branch is for maintain v1.9.

zchee avatar Nov 07 '25 14:11 zchee