fix modernize fmt flag - #135
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the repository’s formatting workflow to align with the current modernize CLI, fixing CI failures in the “Check Code Format” step (Issue #134).
Changes:
- Replace the removed
modernizeflag-category=efaceanywith the current-anyflag in thefmtMakefile target.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fmt: install-imports-formatter | ||
| # replace interface{} with any | ||
| go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -category=efaceany -fix -test ./... | ||
| go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -any -fix -test ./... |
There was a problem hiding this comment.
[P2] 补充当前可复现证据:本次 CI 实际解析到 gopls v0.23.0,它要求 Go 1.26,因此虽然 workflow 声明 Go 1.23,格式步骤仍自动下载并切换到了 Go 1.26.5;在 GOTOOLCHAIN=go1.23.12 下该命令会直接失败。另外,gopls v0.21.0+ 已把这个 gopls/internal/.../cmd/modernize 入口标记为 deprecated,要求迁移到公开的 golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize。因此只替换 flag 仍保留了同一类上游漂移风险。建议改用公开入口、固定工具版本,并让该版本的最低 Go 要求与 CI 明确对齐。
| matrix: | ||
| go_version: | ||
| - '1.23' | ||
| - '1.24' |
There was a problem hiding this comment.
[P1] 保留 Go 1.23 兼容性测试,不要用工具要求替换代码测试矩阵
go.mod 仍声明 go 1.23,而这里是唯一的单测/Lint 矩阵。直接改成 1.24 后,后续代码即使引用 Go 1.24 新增的标准库 API 也会在 CI 通过,但 Go 1.23 用户会编译失败。x/tools v0.38.0 的 Go 1.24 要求只属于格式工具:请保留 Go 1.23 的代码测试任务,并把 format 拆到单独的 Go 1.24 job/step,或仅为该命令显式选择 1.24 工具链;如果项目确实要把最低版本提升到 1.24,则应同时更新 go.mod 和升级说明。
There was a problem hiding this comment.
明确一下,正确的最小改法就是当前 Head c50b47ea:
.github/workflows/github-actions.yml继续使用 Go 1.23,不提升唯一的代码测试矩阵;Makefile中的modernize使用公开入口并固定v0.38.0,只在该命令前设置GOTOOLCHAIN=go1.24.0。
我已在 WSL 验证 GOTOOLCHAIN=go1.23.12 go vet ./...,以及 GOTOOLCHAIN=go1.24.0 go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@v0.38.0 -any -diff -test ./...,两条命令均通过,工作区没有产生改动。这个 P1 在代码层面已经修复,不需要再调整实现;当前新 Head 尚无 checks,接下来只需批准或触发 Actions,并确认检查通过。
What this PR does:
Updates the
fmttarget inMakefileto use the currentmodernizeCLI flag-anyinstead of the removed-category=efaceanyflag.This fixes the GitHub Actions
Check Code Formatstep failure caused bymodernize@latestno longer supporting-category.Which issue(s) this PR fixes:
Fixes #134
Special notes for your reviewer:
Local validation:
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -any -fix -test ./... go fmt ./... imports-formatter go test ./... -coverprofile=coverage.txt -covermode=atomic go vet ./... golangci-lint run ./... --timeout=10mDoes this PR introduce a user-facing change?: