Skip to content

Commit 6fab1b2

Browse files
authored
all: modernize (uber-go#1276)
Run the modernize linter across the codebase. Change generated by running: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... ``` Ref: https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
1 parent 21e34ec commit 6fab1b2

33 files changed

+203
-229
lines changed

annotated.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type Annotated struct {
7979
Group string
8080

8181
// Target is the constructor or value being annotated with fx.Annotated.
82-
Target interface{}
82+
Target any
8383
}
8484

8585
func (a Annotated) String() string {
@@ -116,7 +116,7 @@ var (
116116
// or with [Supply], for a value.
117117
type Annotation interface {
118118
apply(*annotated) error
119-
build(*annotated) (interface{}, error)
119+
build(*annotated) (any, error)
120120
}
121121

122122
var (
@@ -129,7 +129,7 @@ var (
129129
// that it encountered as well as the target interface that was attempted
130130
// to be annotated.
131131
type annotationError struct {
132-
target interface{}
132+
target any
133133
err error
134134
}
135135

@@ -247,7 +247,7 @@ func (pt paramTagsAnnotation) apply(ann *annotated) error {
247247
}
248248

249249
// build builds and returns a constructor after applying a ParamTags annotation
250-
func (pt paramTagsAnnotation) build(ann *annotated) (interface{}, error) {
250+
func (pt paramTagsAnnotation) build(ann *annotated) (any, error) {
251251
paramTypes, remap := pt.parameters(ann)
252252
resultTypes, _ := ann.currentResultTypes()
253253

@@ -390,7 +390,7 @@ func (rt resultTagsAnnotation) apply(ann *annotated) error {
390390
}
391391

392392
// build builds and returns a constructor after applying a ResultTags annotation
393-
func (rt resultTagsAnnotation) build(ann *annotated) (interface{}, error) {
393+
func (rt resultTagsAnnotation) build(ann *annotated) (any, error) {
394394
paramTypes := ann.currentParamTypes()
395395
resultTypes, remapResults := rt.results(ann)
396396
origFn := reflect.ValueOf(ann.Target)
@@ -558,7 +558,7 @@ const (
558558

559559
type lifecycleHookAnnotation struct {
560560
Type _lifecycleHookAnnotationType
561-
Target interface{}
561+
Target any
562562
}
563563

564564
var _ Annotation = (*lifecycleHookAnnotation)(nil)
@@ -625,7 +625,7 @@ func (la *lifecycleHookAnnotation) apply(ann *annotated) error {
625625
}
626626

627627
// build builds and returns a constructor after applying a lifecycle hook annotation.
628-
func (la *lifecycleHookAnnotation) build(ann *annotated) (interface{}, error) {
628+
func (la *lifecycleHookAnnotation) build(ann *annotated) (any, error) {
629629
resultTypes, hasError := ann.currentResultTypes()
630630
if !hasError {
631631
resultTypes = append(resultTypes, _typeOfError)
@@ -809,7 +809,7 @@ func (la *lifecycleHookAnnotation) buildHookInstaller(ann *annotated) (
809809
// parameter is a context, inject the provided context.
810810
if ctxStructPos < 0 {
811811
offset := 0
812-
for i := 0; i < len(hookArgs); i++ {
812+
for i := range hookArgs {
813813
if i == ctxPos {
814814
hookArgs[i] = reflect.ValueOf(ctx)
815815
offset = 1
@@ -887,7 +887,7 @@ var (
887887
// that the lifecycle hook being appended can depend on. It also deduplicates
888888
// duplicate param and result types, which is possible when using fx.Decorate,
889889
// and uses values from results for providing the deduplicated types.
890-
func makeHookScopeCtor(paramTypes []reflect.Type, resultTypes []reflect.Type, args []reflect.Value) interface{} {
890+
func makeHookScopeCtor(paramTypes []reflect.Type, resultTypes []reflect.Type, args []reflect.Value) any {
891891
type key struct {
892892
t reflect.Type
893893
name string
@@ -1112,7 +1112,7 @@ func (la *lifecycleHookAnnotation) buildHook(fn func(context.Context) error) (ho
11121112
// as OnStop. The hook function passed into OnStart cannot take any arguments
11131113
// outside of the annotated constructor's existing dependencies or results, except
11141114
// a context.Context.
1115-
func OnStart(onStart interface{}) Annotation {
1115+
func OnStart(onStart any) Annotation {
11161116
return &lifecycleHookAnnotation{
11171117
Type: _onStartHookType,
11181118
Target: onStart,
@@ -1176,15 +1176,15 @@ func OnStart(onStart interface{}) Annotation {
11761176
// as OnStart. The hook function passed into OnStop cannot take any arguments
11771177
// outside of the annotated constructor's existing dependencies or results, except
11781178
// a context.Context.
1179-
func OnStop(onStop interface{}) Annotation {
1179+
func OnStop(onStop any) Annotation {
11801180
return &lifecycleHookAnnotation{
11811181
Type: _onStopHookType,
11821182
Target: onStop,
11831183
}
11841184
}
11851185

11861186
type asAnnotation struct {
1187-
targets []interface{}
1187+
targets []any
11881188
types []asType
11891189
}
11901190

@@ -1256,7 +1256,7 @@ var _ Annotation = (*asAnnotation)(nil)
12561256
// to maintain the original return types when using As, see [Self].
12571257
//
12581258
// As annotation cannot be used in a function that returns an [Out] struct as a return type.
1259-
func As(interfaces ...interface{}) Annotation {
1259+
func As(interfaces ...any) Annotation {
12601260
return &asAnnotation{targets: interfaces}
12611261
}
12621262

@@ -1311,7 +1311,7 @@ func (at *asAnnotation) apply(ann *annotated) error {
13111311
}
13121312

13131313
// build implements Annotation
1314-
func (at *asAnnotation) build(ann *annotated) (interface{}, error) {
1314+
func (at *asAnnotation) build(ann *annotated) (any, error) {
13151315
paramTypes := ann.currentParamTypes()
13161316

13171317
resultTypes, remapResults, err := at.results(ann)
@@ -1430,7 +1430,7 @@ func extractResultFields(types []reflect.Type) ([]reflect.StructField, func(int,
14301430
}
14311431

14321432
type fromAnnotation struct {
1433-
targets []interface{}
1433+
targets []any
14341434
types []reflect.Type
14351435
}
14361436

@@ -1483,7 +1483,7 @@ var _ Annotation = (*fromAnnotation)(nil)
14831483
//
14841484
// From annotation cannot be used in a function that takes an [In] struct as a
14851485
// parameter.
1486-
func From(interfaces ...interface{}) Annotation {
1486+
func From(interfaces ...any) Annotation {
14871487
return &fromAnnotation{targets: interfaces}
14881488
}
14891489

@@ -1508,7 +1508,7 @@ func (fr *fromAnnotation) apply(ann *annotated) error {
15081508
}
15091509

15101510
// build builds and returns a constructor after applying a From annotation
1511-
func (fr *fromAnnotation) build(ann *annotated) (interface{}, error) {
1511+
func (fr *fromAnnotation) build(ann *annotated) (any, error) {
15121512
paramTypes, remap, err := fr.parameters(ann)
15131513
if err != nil {
15141514
return nil, err
@@ -1613,7 +1613,7 @@ func (fr *fromAnnotation) parameters(ann *annotated) (
16131613
}
16141614

16151615
type annotated struct {
1616-
Target interface{}
1616+
Target any
16171617
Annotations []Annotation
16181618
ParamTags []string
16191619
ResultTags []string
@@ -1647,7 +1647,7 @@ func (ann annotated) String() string {
16471647

16481648
// Build builds and returns a constructor based on fx.In/fx.Out params and
16491649
// results wrapping the original constructor passed to fx.Annotate.
1650-
func (ann *annotated) Build() (interface{}, error) {
1650+
func (ann *annotated) Build() (any, error) {
16511651
ann.container = dig.New()
16521652
ft := reflect.TypeOf(ann.Target)
16531653
if ft.Kind() != reflect.Func {
@@ -1758,7 +1758,7 @@ func (ann *annotated) cleanUpAsResults() {
17581758
func (ann *annotated) typeCheckOrigFn() error {
17591759
ft := reflect.TypeOf(ann.Target)
17601760
numOut := ft.NumOut()
1761-
for i := 0; i < numOut; i++ {
1761+
for i := range numOut {
17621762
ot := ft.Out(i)
17631763
if ot == _typeOfError && i != numOut-1 {
17641764
return fmt.Errorf(
@@ -1796,7 +1796,7 @@ func (ann *annotated) currentResultTypes() (resultTypes []reflect.Type, hasError
17961796
numOut := ft.NumOut()
17971797
resultTypes = make([]reflect.Type, numOut)
17981798

1799-
for i := 0; i < numOut; i++ {
1799+
for i := range numOut {
18001800
resultTypes[i] = ft.Out(i)
18011801
if resultTypes[i] == _typeOfError && i == numOut-1 {
18021802
hasError = true
@@ -1898,7 +1898,7 @@ func (ann *annotated) currentParamTypes() []reflect.Type {
18981898
// Target: func(..) http.Handler { ... },
18991899
// Group: "server",
19001900
// }
1901-
func Annotate(t interface{}, anns ...Annotation) interface{} {
1901+
func Annotate(t any, anns ...Annotation) any {
19021902
result := annotated{Target: t}
19031903
for _, ann := range anns {
19041904
if err := ann.apply(&result); err != nil {

annotated_test.go

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestAnnotatedFrom(t *testing.T) {
110110
tests := []struct {
111111
desc string
112112
provide fx.Option
113-
invoke interface{}
113+
invoke any
114114
}{
115115
{
116116
desc: "provide a good stringer",
@@ -275,7 +275,6 @@ func TestAnnotatedFrom(t *testing.T) {
275275
}
276276

277277
for _, tt := range tests {
278-
tt := tt
279278
t.Run(tt.desc, func(t *testing.T) {
280279
t.Parallel()
281280

@@ -304,7 +303,7 @@ func TestAnnotatedFromFailures(t *testing.T) {
304303
tests := []struct {
305304
desc string
306305
provide fx.Option
307-
invoke interface{}
306+
invoke any
308307
errorContains string
309308
}{
310309
{
@@ -409,7 +408,6 @@ func TestAnnotatedFromFailures(t *testing.T) {
409408
}
410409

411410
for _, tt := range tests {
412-
tt := tt
413411
t.Run(tt.desc, func(t *testing.T) {
414412
t.Parallel()
415413
app := NewForTest(t,
@@ -452,7 +450,7 @@ func TestAnnotatedAs(t *testing.T) {
452450
tests := []struct {
453451
desc string
454452
provide fx.Option
455-
invoke interface{}
453+
invoke any
456454
startApp bool
457455
}{
458456
{
@@ -802,7 +800,6 @@ func TestAnnotatedAs(t *testing.T) {
802800
}
803801

804802
for _, tt := range tests {
805-
tt := tt
806803
t.Run(tt.desc, func(t *testing.T) {
807804
t.Parallel()
808805

@@ -837,7 +834,7 @@ func TestAnnotatedAsFailures(t *testing.T) {
837834
tests := []struct {
838835
desc string
839836
provide fx.Option
840-
invoke interface{}
837+
invoke any
841838
errorContains string
842839
}{
843840
{
@@ -895,7 +892,6 @@ func TestAnnotatedAsFailures(t *testing.T) {
895892
}
896893

897894
for _, tt := range tests {
898-
tt := tt
899895
t.Run(tt.desc, func(t *testing.T) {
900896
t.Parallel()
901897
app := NewForTest(t,
@@ -1044,7 +1040,6 @@ func TestAnnotatedString(t *testing.T) {
10441040
}
10451041

10461042
for _, tt := range tests {
1047-
tt := tt
10481043
t.Run(tt.desc, func(t *testing.T) {
10491044
t.Parallel()
10501045

@@ -1108,7 +1103,7 @@ func TestAnnotate(t *testing.T) {
11081103
app := fxtest.New(t,
11091104
fx.Provide(
11101105
fx.Annotate(newB, fx.ParamTags(`optional:"true"`)),
1111-
fx.Annotate(func(a *a, b *b) interface{} { return nil },
1106+
fx.Annotate(func(a *a, b *b) any { return nil },
11121107
fx.ParamTags(`name:"a" optional:"true"`, `name:"b"`),
11131108
fx.ResultTags(`name:"nil"`),
11141109
),
@@ -1553,7 +1548,7 @@ func TestAnnotate(t *testing.T) {
15531548
t.Run("annotate a fx.Out with As", func(t *testing.T) {
15541549
t.Parallel()
15551550

1556-
type I interface{}
1551+
type I any
15571552

15581553
type B struct {
15591554
// implements I
@@ -1606,7 +1601,7 @@ func TestAnnotate(t *testing.T) {
16061601
t.Run("annotate a fx.In with From", func(t *testing.T) {
16071602
t.Parallel()
16081603

1609-
type I interface{}
1604+
type I any
16101605

16111606
type B struct {
16121607
// implements I
@@ -1903,7 +1898,7 @@ func TestHookAnnotations(t *testing.T) {
19031898
t.Run("start and stop without dependencies", func(t *testing.T) {
19041899
t.Parallel()
19051900

1906-
type stub interface{}
1901+
type stub any
19071902

19081903
var (
19091904
invoked bool
@@ -1937,9 +1932,9 @@ func TestHookAnnotations(t *testing.T) {
19371932
t.Parallel()
19381933

19391934
type (
1940-
A interface{}
1941-
B interface{}
1942-
C interface{}
1935+
A any
1936+
B any
1937+
C any
19431938
)
19441939

19451940
var value int
@@ -2111,7 +2106,7 @@ func TestHookAnnotations(t *testing.T) {
21112106
t.Run("with Supply and Decorate", func(t *testing.T) {
21122107
t.Parallel()
21132108

2114-
type A interface{}
2109+
type A any
21152110

21162111
ch := make(chan string, 3)
21172112

@@ -2178,7 +2173,7 @@ func TestHookAnnotations(t *testing.T) {
21782173
app := fxtest.New(t,
21792174
fx.Provide(
21802175
fx.Annotate(newB, fx.ParamTags(`optional:"true"`)),
2181-
fx.Annotate(func(a *a, b *b) interface{} { return nil },
2176+
fx.Annotate(func(a *a, b *b) any { return nil },
21822177
fx.ParamTags(`name:"a" optional:"true"`, `name:"b"`),
21832178
fx.ResultTags(`name:"nil"`),
21842179
fx.OnStart(func(_ paramStruct) error {
@@ -2287,8 +2282,8 @@ func TestHookAnnotationFailures(t *testing.T) {
22872282
}
22882283

22892284
type (
2290-
A interface{}
2291-
B interface{}
2285+
A any
2286+
B any
22922287
)
22932288

22942289
type namedAndGroupHookParams struct {
@@ -2311,7 +2306,7 @@ func TestHookAnnotationFailures(t *testing.T) {
23112306

23122307
table := []struct {
23132308
name string
2314-
annotation interface{}
2309+
annotation any
23152310
extraOpts fx.Option
23162311
useNew bool
23172312
errContains string
@@ -2450,7 +2445,6 @@ func TestHookAnnotationFailures(t *testing.T) {
24502445
}
24512446

24522447
for _, tt := range table {
2453-
tt := tt
24542448
t.Run(tt.name, func(t *testing.T) {
24552449
t.Parallel()
24562450
opts := fx.Options(
@@ -2478,11 +2472,11 @@ func TestHookAnnotationFailures(t *testing.T) {
24782472
}
24792473

24802474
func TestHookAnnotationFunctionFlexibility(t *testing.T) {
2481-
type A interface{}
2475+
type A any
24822476

24832477
table := []struct {
24842478
name string
2485-
annotation interface{}
2479+
annotation any
24862480
}{
24872481
{
24882482
name: "without error return",
@@ -2525,7 +2519,6 @@ func TestHookAnnotationFunctionFlexibility(t *testing.T) {
25252519
}
25262520

25272521
for _, tt := range table {
2528-
tt := tt
25292522
t.Run(tt.name, func(t *testing.T) {
25302523
var (
25312524
called atomic.Bool

0 commit comments

Comments
 (0)