mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
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:
@@ -27,7 +27,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -25,7 +25,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -22,7 +22,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -34,7 +34,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
// This threshold should be lowered to 50 over time.
|
||||
const over = 100
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspectResult, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -23,7 +23,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -33,7 +33,7 @@ var selectedInterfaces = []string{
|
||||
"interface.WriteOnlyBeaconState",
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -29,7 +29,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -18,7 +18,7 @@ const Doc = "This analyzer requires that log statements do not use errors in tem
|
||||
const errImproperUsage = "use log.WithError rather than templated log statements with errors"
|
||||
|
||||
// Map of logrus templated log functions.
|
||||
var logFns = map[string]interface{}{
|
||||
var logFns = map[string]any{
|
||||
"Debugf": nil,
|
||||
"Infof": nil,
|
||||
"Printf": nil,
|
||||
@@ -37,7 +37,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -22,7 +22,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -38,7 +38,7 @@ func optimalSort(sizes gcSizes, str *types.Struct) string {
|
||||
fields := make([]*types.Var, nf)
|
||||
alignofs := make([]int64, nf)
|
||||
sizeofs := make([]int64, nf)
|
||||
for i := 0; i < nf; i++ {
|
||||
for i := range nf {
|
||||
fields[i] = str.Field(i)
|
||||
ft := fields[i].Type()
|
||||
alignofs[i] = sizes.Alignof(ft)
|
||||
@@ -62,7 +62,7 @@ func optimalSize(str *types.Struct, sizes *gcSizes) int64 {
|
||||
fields := make([]*types.Var, nf)
|
||||
alignofs := make([]int64, nf)
|
||||
sizeofs := make([]int64, nf)
|
||||
for i := 0; i < nf; i++ {
|
||||
for i := range nf {
|
||||
fields[i] = str.Field(i)
|
||||
ft := fields[i].Type()
|
||||
alignofs[i] = sizes.Alignof(ft)
|
||||
@@ -197,7 +197,7 @@ func (s *gcSizes) Sizeof(T types.Type) int64 {
|
||||
|
||||
var o int64
|
||||
max := int64(1)
|
||||
for i := 0; i < nf; i++ {
|
||||
for i := range nf {
|
||||
ft := t.Field(i).Type()
|
||||
a, sz := s.Alignof(ft), s.Sizeof(ft)
|
||||
if a > max {
|
||||
|
||||
5
tools/analyzers/modernize/README.md
Normal file
5
tools/analyzers/modernize/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Modernize
|
||||
|
||||
These are analyzers that are re-exported from golang.org/x/tools/go/analysis/passes/modernize.
|
||||
|
||||
nogo expects a package to contain a single analyzer, while modernize exposes the named analyzers and an analyzer suite. This is incompatible with nogo so we have re-exported each analyzer.
|
||||
9
tools/analyzers/modernize/any/BUILD.bazel
Normal file
9
tools/analyzers/modernize/any/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/any",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/any/analyzer.go
Normal file
5
tools/analyzers/modernize/any/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package any
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.AnyAnalyzer
|
||||
9
tools/analyzers/modernize/appendclipped/BUILD.bazel
Normal file
9
tools/analyzers/modernize/appendclipped/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/appendclipped",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/appendclipped/analyzer.go
Normal file
5
tools/analyzers/modernize/appendclipped/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package appendclipped
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.AppendClippedAnalyzer
|
||||
9
tools/analyzers/modernize/bloop/BUILD.bazel
Normal file
9
tools/analyzers/modernize/bloop/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/bloop",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/bloop/analyzer.go
Normal file
5
tools/analyzers/modernize/bloop/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package bloop
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.BLoopAnalyzer
|
||||
9
tools/analyzers/modernize/fmtappendf/BUILD.bazel
Normal file
9
tools/analyzers/modernize/fmtappendf/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/fmtappendf",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/fmtappendf/analyzer.go
Normal file
5
tools/analyzers/modernize/fmtappendf/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package fmtappendf
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.FmtAppendfAnalyzer
|
||||
9
tools/analyzers/modernize/forvar/BUILD.bazel
Normal file
9
tools/analyzers/modernize/forvar/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/forvar",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/forvar/analyzer.go
Normal file
5
tools/analyzers/modernize/forvar/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package forvar
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.ForVarAnalyzer
|
||||
9
tools/analyzers/modernize/mapsloop/BUILD.bazel
Normal file
9
tools/analyzers/modernize/mapsloop/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/mapsloop",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/mapsloop/analyzer.go
Normal file
5
tools/analyzers/modernize/mapsloop/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package mapsloop
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.MapsLoopAnalyzer
|
||||
9
tools/analyzers/modernize/minmax/BUILD.bazel
Normal file
9
tools/analyzers/modernize/minmax/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/minmax",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/minmax/analyzer.go
Normal file
5
tools/analyzers/modernize/minmax/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package minmax
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.MinMaxAnalyzer
|
||||
9
tools/analyzers/modernize/newexpr/BUILD.bazel
Normal file
9
tools/analyzers/modernize/newexpr/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/newexpr",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/newexpr/analyzer.go
Normal file
5
tools/analyzers/modernize/newexpr/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package newexpr
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.NewExprAnalyzer
|
||||
9
tools/analyzers/modernize/omitzero/BUILD.bazel
Normal file
9
tools/analyzers/modernize/omitzero/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/omitzero",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/omitzero/analyzer.go
Normal file
5
tools/analyzers/modernize/omitzero/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package omitzero
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.OmitZeroAnalyzer
|
||||
9
tools/analyzers/modernize/rangeint/BUILD.bazel
Normal file
9
tools/analyzers/modernize/rangeint/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/rangeint",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/rangeint/analyzer.go
Normal file
5
tools/analyzers/modernize/rangeint/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package rangeint
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.RangeIntAnalyzer
|
||||
9
tools/analyzers/modernize/reflecttypefor/BUILD.bazel
Normal file
9
tools/analyzers/modernize/reflecttypefor/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/reflecttypefor",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/reflecttypefor/analyzer.go
Normal file
5
tools/analyzers/modernize/reflecttypefor/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package reflecttypefor
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.ReflectTypeForAnalyzer
|
||||
9
tools/analyzers/modernize/slicescontains/BUILD.bazel
Normal file
9
tools/analyzers/modernize/slicescontains/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/slicescontains",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/slicescontains/analyzer.go
Normal file
5
tools/analyzers/modernize/slicescontains/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package slicescontains
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.SlicesContainsAnalyzer
|
||||
9
tools/analyzers/modernize/slicesdelete/BUILD.bazel
Normal file
9
tools/analyzers/modernize/slicesdelete/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/slicesdelete",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/slicesdelete/analyzer.go
Normal file
5
tools/analyzers/modernize/slicesdelete/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package slicesdelete
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.SlicesDeleteAnalyzer
|
||||
9
tools/analyzers/modernize/slicessort/BUILD.bazel
Normal file
9
tools/analyzers/modernize/slicessort/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/slicessort",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/slicessort/analyzer.go
Normal file
5
tools/analyzers/modernize/slicessort/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package slicessort
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.SlicesSortAnalyzer
|
||||
9
tools/analyzers/modernize/stringsbuilder/BUILD.bazel
Normal file
9
tools/analyzers/modernize/stringsbuilder/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/stringsbuilder",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/stringsbuilder/analyzer.go
Normal file
5
tools/analyzers/modernize/stringsbuilder/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package stringsbuilder
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.StringsBuilderAnalyzer
|
||||
9
tools/analyzers/modernize/stringscutprefix/BUILD.bazel
Normal file
9
tools/analyzers/modernize/stringscutprefix/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/stringscutprefix",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/stringscutprefix/analyzer.go
Normal file
5
tools/analyzers/modernize/stringscutprefix/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package stringscutprefix
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.StringsCutPrefixAnalyzer
|
||||
9
tools/analyzers/modernize/stringsseq/BUILD.bazel
Normal file
9
tools/analyzers/modernize/stringsseq/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/stringsseq",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/stringsseq/analyzer.go
Normal file
5
tools/analyzers/modernize/stringsseq/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package stringsseq
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.StringsSeqAnalyzer
|
||||
9
tools/analyzers/modernize/testingcontext/BUILD.bazel
Normal file
9
tools/analyzers/modernize/testingcontext/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/testingcontext",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/testingcontext/analyzer.go
Normal file
5
tools/analyzers/modernize/testingcontext/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package testingcontext
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.TestingContextAnalyzer
|
||||
9
tools/analyzers/modernize/waitgroup/BUILD.bazel
Normal file
9
tools/analyzers/modernize/waitgroup/BUILD.bazel
Normal file
@@ -0,0 +1,9 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["analyzer.go"],
|
||||
importpath = "github.com/OffchainLabs/prysm/v7/tools/analyzers/modernize/waitgroup",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@org_golang_x_tools//go/analysis/passes/modernize:go_default_library"],
|
||||
)
|
||||
5
tools/analyzers/modernize/waitgroup/analyzer.go
Normal file
5
tools/analyzers/modernize/waitgroup/analyzer.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package waitgroup
|
||||
|
||||
import "golang.org/x/tools/go/analysis/passes/modernize"
|
||||
|
||||
var Analyzer = modernize.WaitGroupAnalyzer
|
||||
@@ -25,7 +25,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -22,7 +22,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -31,7 +31,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -65,7 +65,7 @@ func (m mode) ErrorFound() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspectResult, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
@@ -163,7 +163,7 @@ func stmtSelector(node ast.Node, pass *analysis.Pass, keepTrackOf *tracker, insp
|
||||
}
|
||||
case *ast.IfStmt:
|
||||
stmts := stmt.Body.List
|
||||
for i := 0; i < len(stmts); i++ {
|
||||
for i := range stmts {
|
||||
keepTrackOf = stmtSelector(stmts[i], pass, keepTrackOf, inspect)
|
||||
}
|
||||
keepTrackOf = stmtSelector(stmt.Else, pass, keepTrackOf, inspect)
|
||||
|
||||
@@ -32,7 +32,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -23,7 +23,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -24,7 +24,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
Run: run,
|
||||
}
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
func run(pass *analysis.Pass) (any, error) {
|
||||
inspection, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
if !ok {
|
||||
return nil, errors.New("analyzer is not type *inspector.Inspector")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/OffchainLabs/prysm/v7/io/file"
|
||||
@@ -61,11 +62,11 @@ func main() {
|
||||
}
|
||||
|
||||
func sszBytesToMapStr(ss map[int][]byte) string {
|
||||
dst := ""
|
||||
var dst strings.Builder
|
||||
for i, s := range ss {
|
||||
dst += fmt.Sprintf("%d: \"%x\",", i, s)
|
||||
dst.WriteString(fmt.Sprintf("%d: \"%x\",", i, s))
|
||||
}
|
||||
return dst
|
||||
return dst.String()
|
||||
}
|
||||
|
||||
type input struct {
|
||||
@@ -74,7 +75,7 @@ type input struct {
|
||||
MapStr string
|
||||
}
|
||||
|
||||
func execTmpl(tpl string, input interface{}) *bytes.Buffer {
|
||||
func execTmpl(tpl string, input any) *bytes.Buffer {
|
||||
tmpl, err := template.New("template").Parse(tpl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -56,7 +56,7 @@ func main() {
|
||||
|
||||
// Construct nodes
|
||||
m := make(map[[32]byte]*node)
|
||||
for i := 0; i < len(blks); i++ {
|
||||
for i := range blks {
|
||||
b := blks[i]
|
||||
r := roots[i]
|
||||
m[r] = &node{score: make(map[uint64]bool)}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (h *handler) httpHandler(w http.ResponseWriter, _ *http.Request) {
|
||||
allNodes := h.listener.AllNodes()
|
||||
write(w, []byte("Nodes stored in the table:\n"))
|
||||
for i, n := range allNodes {
|
||||
write(w, []byte(fmt.Sprintf("Node %d\n", i)))
|
||||
write(w, fmt.Appendf(nil, "Node %d\n", i))
|
||||
write(w, []byte(n.String()+"\n"))
|
||||
write(w, []byte("Node ID: "+n.ID().String()+"\n"))
|
||||
write(w, []byte("IP: "+n.IP().String()+"\n"))
|
||||
|
||||
@@ -270,7 +270,7 @@ func readStates(ctx context.Context, db *kv.Store, stateC chan<- *modifiedState,
|
||||
stateMap[uint64(st.Slot())] = mst
|
||||
}
|
||||
|
||||
for i := uint64(0); i < maxSlotsToDisplay; i++ {
|
||||
for i := range uint64(maxSlotsToDisplay) {
|
||||
if _, ok := stateMap[i]; ok {
|
||||
stateC <- stateMap[i]
|
||||
}
|
||||
@@ -502,14 +502,14 @@ func sizeAndCountOfByteList(list [][]byte) (uint64, uint64) {
|
||||
func sizeAndCountOfUin64List(list []uint64) (uint64, uint64) {
|
||||
size := uint64(0)
|
||||
count := uint64(0)
|
||||
for i := 0; i < len(list); i++ {
|
||||
for range list {
|
||||
size += uint64(8)
|
||||
count += 1
|
||||
}
|
||||
return size, count
|
||||
}
|
||||
|
||||
func sizeAndCountGeneric(genericItems interface{}, err error) (uint64, uint64) {
|
||||
func sizeAndCountGeneric(genericItems any, err error) (uint64, uint64) {
|
||||
size := uint64(0)
|
||||
count := uint64(0)
|
||||
if err != nil {
|
||||
|
||||
@@ -42,7 +42,7 @@ func main() {
|
||||
}()
|
||||
|
||||
http.HandleFunc("/", func(writer http.ResponseWriter, r *http.Request) {
|
||||
reqContent := map[string]interface{}{}
|
||||
reqContent := map[string]any{}
|
||||
if err = parseRequest(r, &reqContent); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func main() {
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
|
||||
func captureRequest(f *os.File, m map[string]interface{}) error {
|
||||
func captureRequest(f *os.File, m map[string]any) error {
|
||||
enc, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -68,7 +68,7 @@ func captureRequest(f *os.File, m map[string]interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func parseRequest(req *http.Request, unmarshalStruct interface{}) error {
|
||||
func parseRequest(req *http.Request, unmarshalStruct any) error {
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -31,7 +31,7 @@ func Test_parseAndCaptureRequest(t *testing.T) {
|
||||
httpReq, err := http.NewRequest("GET", "/", bytes.NewBuffer(enc))
|
||||
require.NoError(t, err)
|
||||
|
||||
reqContent := map[string]interface{}{}
|
||||
reqContent := map[string]any{}
|
||||
err = parseRequest(httpReq, &reqContent)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -52,7 +52,7 @@ func Test_parseAndCaptureRequest(t *testing.T) {
|
||||
fileContents, err := io.ReadAll(f)
|
||||
require.NoError(t, err)
|
||||
|
||||
receivedContent := map[string]interface{}{}
|
||||
receivedContent := map[string]any{}
|
||||
err = json.Unmarshal(fileContents, &receivedContent)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func generateKeysFromMnemonicList(mnemonicListFile *bufio.Scanner, keysPerMnemon
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for i := 0; i < keysPerMnemonic; i++ {
|
||||
for i := range keysPerMnemonic {
|
||||
if i%250 == 0 && i > 0 {
|
||||
log.Printf("%d/%d keys generated\n", i, keysPerMnemonic)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func spreadKeysAcrossLocalWallets(
|
||||
walletPassword string,
|
||||
) error {
|
||||
ctx := context.Background()
|
||||
for i := 0; i < numWallets; i++ {
|
||||
for i := range numWallets {
|
||||
w := wallet.New(&wallet.Config{
|
||||
WalletDir: path.Join(walletOutputDir, fmt.Sprintf("wallet_%d", i)),
|
||||
KeymanagerKind: keymanager.Local,
|
||||
|
||||
@@ -69,7 +69,7 @@ func Test_spreadKeysAcrossImportedWallets(t *testing.T) {
|
||||
)
|
||||
require.NoError(t, err)
|
||||
ctx := t.Context()
|
||||
for i := 0; i < numWallets; i++ {
|
||||
for i := range numWallets {
|
||||
w, err := wallet.OpenWallet(ctx, &wallet.Config{
|
||||
WalletDir: filepath.Join(tmpDir, fmt.Sprintf("wallet_%d", i)),
|
||||
KeymanagerKind: keymanager.Local,
|
||||
|
||||
@@ -68,7 +68,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
for _, check := range strings.Split(*checks, ",") {
|
||||
for check := range strings.SplitSeq(*checks, ",") {
|
||||
c.AddExclusion(strings.TrimSpace(check), e)
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ func matchesRefImplementation(defName string, refDefs []string, input string, po
|
||||
inputLines := strings.Split(strings.TrimRight(input, "\n"), "\n")
|
||||
|
||||
matchesPerfectly := true
|
||||
for i := 0; i < len(refDefLines); i++ {
|
||||
for i := range refDefLines {
|
||||
a, b := strings.Trim(refDefLines[i], " "), strings.Trim(inputLines[i], " ")
|
||||
if a != b {
|
||||
matchesPerfectly = false
|
||||
|
||||
@@ -67,7 +67,7 @@ func generateRandomKeys(num int) (*keygen.UnencryptedKeysContainer, error) {
|
||||
Keys: make([]*keygen.UnencryptedKeys, num),
|
||||
}
|
||||
|
||||
for i := 0; i < num; i++ {
|
||||
for i := range num {
|
||||
sk, err := bls.RandKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user