Add golang.org/x/tools modernize static analyzer and fix violations (#15946)

* Ran gopls modernize to fix everything

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

* Override rules_go provided dependency for golang.org/x/tools to v0.38.0.

To update this, checked out rules_go, then ran `bazel run //go/tools/releaser -- upgrade-dep -mirror=false org_golang_x_tools` and copied the patches.

* Fix buildtag violations and ignore buildtag violations in external

* Introduce modernize analyzer package.

* Add modernize "any" analyzer.

* Fix violations of any analyzer

* Add modernize "appendclipped" analyzer.

* Fix violations of appendclipped

* Add modernize "bloop" analyzer.

* Add modernize "fmtappendf" analyzer.

* Add modernize "forvar" analyzer.

* Add modernize "mapsloop" analyzer.

* Add modernize "minmax" analyzer.

* Fix violations of minmax analyzer

* Add modernize "omitzero" analyzer.

* Add modernize "rangeint" analyzer.

* Fix violations of rangeint.

* Add modernize "reflecttypefor" analyzer.

* Fix violations of reflecttypefor analyzer.

* Add modernize "slicescontains" analyzer.

* Add modernize "slicessort" analyzer.

* Add modernize "slicesdelete" analyzer. This is disabled by default for now. See https://go.dev/issue/73686.

* Add modernize "stringscutprefix" analyzer.

* Add modernize "stringsbuilder" analyzer.

* Fix violations of stringsbuilder analyzer.

* Add modernize "stringsseq" analyzer.

* Add modernize "testingcontext" analyzer.

* Add modernize "waitgroup" analyzer.

* Changelog fragment

* gofmt

* gazelle

* Add modernize "newexpr" analyzer.

* Disable newexpr until go1.26

* Add more details in WORKSPACE on how to update the override

* @nalepae feedback on min()

* gofmt

* Fix violations of forvar
This commit is contained in:
Preston Van Loon
2025-11-13 19:27:22 -06:00
committed by GitHub
parent f77b78943a
commit 2fd6bd8150
605 changed files with 217475 additions and 2228 deletions

View File

@@ -46,7 +46,7 @@ func TestConfig_OverrideBeaconConfigTestTeardown(t *testing.T) {
func TestConfig_DataRace(t *testing.T) {
params.SetupTestConfigCleanup(t)
wg := new(sync.WaitGroup)
for i := 0; i < 10; i++ {
for range 10 {
wg.Add(2)
go func() {
defer wg.Done()
@@ -197,7 +197,7 @@ func Test_TargetBlobCount(t *testing.T) {
func fillGVR(value byte) [32]byte {
var gvr [32]byte
for i := 0; i < len(gvr); i++ {
for i := range len(gvr) {
gvr[i] = value
}
return gvr
@@ -232,7 +232,6 @@ func TestBeaconChainConfigSlotDuration(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, tt.cfg.SlotDuration())
@@ -266,7 +265,6 @@ func TestBeaconChainConfigSlotDurationMillis(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, tt.cfg.SlotDurationMillis())
@@ -316,7 +314,6 @@ func TestBeaconChainConfigSlotComponentDuration(t *testing.T) {
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, tt.cfg.SlotComponentDuration(tt.bp))

View File

@@ -401,7 +401,7 @@ func fieldsFromYamls(t *testing.T, fps []string) []string {
for _, fp := range fps {
yamlFile, err := os.ReadFile(fp)
require.NoError(t, err)
m := make(map[string]interface{})
m := make(map[string]any)
require.NoError(t, yaml.Unmarshal(yamlFile, &m))
for k := range m {
@@ -421,7 +421,7 @@ func fieldsFromYamls(t *testing.T, fps []string) []string {
func assertYamlFieldsMatch(t *testing.T, name string, fields []string, c1, c2 *params.BeaconChainConfig) {
// Ensure all fields from the yaml file exist, were set, and correctly match the expected value.
ft1 := reflect.TypeOf(*c1)
ft1 := reflect.TypeFor[params.BeaconChainConfig]()
for _, field := range fields {
var found bool
for i := 0; i < ft1.NumField(); i++ {

View File

@@ -16,7 +16,7 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
)
func UnmarshalFromURL(ctx context.Context, from string, to interface{}) error {
func UnmarshalFromURL(ctx context.Context, from string, to any) error {
u, err := url.ParseRequestURI(from)
if err != nil {
return err
@@ -48,7 +48,7 @@ func UnmarshalFromURL(ctx context.Context, from string, to interface{}) error {
return nil
}
func UnmarshalFromFile(from string, to interface{}) error {
func UnmarshalFromFile(from string, to any) error {
cleanpath := filepath.Clean(from)
b, err := os.ReadFile(cleanpath)
if err != nil {