Rewrite 'interface{} -> any' (#1959)

## Changes

The `any` alias for `interface{}` has been around since Go 1.18.

Now that we're using golangci-lint (#1953), we can lint on it.

Existing commits can be updated with:
```
gofmt -w -r 'interface{} -> any' .
```

## Tests

n/a
This commit is contained in:
Pieter Noordhuis 2024-12-05 16:37:24 +01:00 committed by GitHub
parent 7ffe93e4d0
commit 6e754d4f34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 60 additions and 58 deletions

View File

@ -15,5 +15,7 @@ linters-settings:
rewrite-rules: rewrite-rules:
- pattern: 'a[b:len(a)]' - pattern: 'a[b:len(a)]'
replacement: 'a[b:]' replacement: 'a[b:]'
- pattern: 'interface{}'
replacement: 'any'
issues: issues:
exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/ exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/

View File

@ -133,7 +133,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
"complex": { "complex": {
Type: variable.VariableTypeComplex, Type: variable.VariableTypeComplex,
Description: "complex var", Description: "complex var",
Default: map[string]interface{}{ Default: map[string]any{
"key": "value", "key": "value",
}, },
}, },
@ -148,7 +148,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
"complex": { "complex": {
Type: "wrong", Type: "wrong",
Description: "wrong", Description: "wrong",
Default: map[string]interface{}{ Default: map[string]any{
"key1": "value1", "key1": "value1",
}, },
}, },
@ -164,7 +164,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
assert.Equal(t, "foo2", root.Variables["foo2"].Default) assert.Equal(t, "foo2", root.Variables["foo2"].Default)
assert.Equal(t, "foo2 var", root.Variables["foo2"].Description) assert.Equal(t, "foo2 var", root.Variables["foo2"].Description)
assert.Equal(t, map[string]interface{}{ assert.Equal(t, map[string]any{
"key1": "value1", "key1": "value1",
}, root.Variables["complex"].Default) }, root.Variables["complex"].Default)
assert.Equal(t, "complex var", root.Variables["complex"].Description) assert.Equal(t, "complex var", root.Variables["complex"].Description)

View File

@ -15,10 +15,10 @@ import (
) )
func (s *Schema) writeTerraformBlock(_ context.Context) error { func (s *Schema) writeTerraformBlock(_ context.Context) error {
var body = map[string]interface{}{ var body = map[string]any{
"terraform": map[string]interface{}{ "terraform": map[string]any{
"required_providers": map[string]interface{}{ "required_providers": map[string]any{
"databricks": map[string]interface{}{ "databricks": map[string]any{
"source": "databricks/databricks", "source": "databricks/databricks",
"version": ProviderVersion, "version": ProviderVersion,
}, },

View File

@ -25,9 +25,9 @@ const ProviderVersion = "1.59.0"
func NewRoot() *Root { func NewRoot() *Root {
return &Root{ return &Root{
Terraform: map[string]interface{}{ Terraform: map[string]any{
"required_providers": map[string]interface{}{ "required_providers": map[string]any{
"databricks": map[string]interface{}{ "databricks": map[string]any{
"source": ProviderSource, "source": ProviderSource,
"version": ProviderVersion, "version": ProviderVersion,
}, },

View File

@ -23,10 +23,10 @@ var renderFuncMap = template.FuncMap{
"yellow": color.YellowString, "yellow": color.YellowString,
"magenta": color.MagentaString, "magenta": color.MagentaString,
"cyan": color.CyanString, "cyan": color.CyanString,
"bold": func(format string, a ...interface{}) string { "bold": func(format string, a ...any) string {
return color.New(color.Bold).Sprintf(format, a...) return color.New(color.Bold).Sprintf(format, a...)
}, },
"italic": func(format string, a ...interface{}) string { "italic": func(format string, a ...any) string {
return color.New(color.Italic).Sprintf(format, a...) return color.New(color.Italic).Sprintf(format, a...)
}, },
} }

View File

@ -15,7 +15,7 @@ type LogsOutput struct {
LogsTruncated bool `json:"logs_truncated"` LogsTruncated bool `json:"logs_truncated"`
} }
func structToString(val interface{}) (string, error) { func structToString(val any) (string, error) {
b, err := json.MarshalIndent(val, "", " ") b, err := json.MarshalIndent(val, "", " ")
if err != nil { if err != nil {
return "", err return "", err

View File

@ -104,5 +104,5 @@ func TestComplexVariablesOverrideWithFullSyntax(t *testing.T) {
require.Empty(t, diags) require.Empty(t, diags)
complexvar := b.Config.Variables["complexvar"].Value complexvar := b.Config.Variables["complexvar"].Value
require.Equal(t, map[string]interface{}{"key1": "1", "key2": "2", "key3": "3"}, complexvar) require.Equal(t, map[string]any{"key1": "1", "key2": "2", "key3": "3"}, complexvar)
} }

View File

@ -276,7 +276,7 @@ func (t *cobraTestRunner) Run() (bytes.Buffer, bytes.Buffer, error) {
} }
// Like [require.Eventually] but errors if the underlying command has failed. // Like [require.Eventually] but errors if the underlying command has failed.
func (c *cobraTestRunner) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { func (c *cobraTestRunner) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...any) {
ch := make(chan bool, 1) ch := make(chan bool, 1)
timer := time.NewTimer(waitFor) timer := time.NewTimer(waitFor)

View File

@ -28,11 +28,11 @@ func (_m *MockFiler) EXPECT() *MockFiler_Expecter {
// Delete provides a mock function with given fields: ctx, path, mode // Delete provides a mock function with given fields: ctx, path, mode
func (_m *MockFiler) Delete(ctx context.Context, path string, mode ...filer.DeleteMode) error { func (_m *MockFiler) Delete(ctx context.Context, path string, mode ...filer.DeleteMode) error {
_va := make([]interface{}, len(mode)) _va := make([]any, len(mode))
for _i := range mode { for _i := range mode {
_va[_i] = mode[_i] _va[_i] = mode[_i]
} }
var _ca []interface{} var _ca []any
_ca = append(_ca, ctx, path) _ca = append(_ca, ctx, path)
_ca = append(_ca, _va...) _ca = append(_ca, _va...)
ret := _m.Called(_ca...) ret := _m.Called(_ca...)
@ -60,9 +60,9 @@ type MockFiler_Delete_Call struct {
// - ctx context.Context // - ctx context.Context
// - path string // - path string
// - mode ...filer.DeleteMode // - mode ...filer.DeleteMode
func (_e *MockFiler_Expecter) Delete(ctx interface{}, path interface{}, mode ...interface{}) *MockFiler_Delete_Call { func (_e *MockFiler_Expecter) Delete(ctx any, path any, mode ...any) *MockFiler_Delete_Call {
return &MockFiler_Delete_Call{Call: _e.mock.On("Delete", return &MockFiler_Delete_Call{Call: _e.mock.On("Delete",
append([]interface{}{ctx, path}, mode...)...)} append([]any{ctx, path}, mode...)...)}
} }
func (_c *MockFiler_Delete_Call) Run(run func(ctx context.Context, path string, mode ...filer.DeleteMode)) *MockFiler_Delete_Call { func (_c *MockFiler_Delete_Call) Run(run func(ctx context.Context, path string, mode ...filer.DeleteMode)) *MockFiler_Delete_Call {
@ -114,7 +114,7 @@ type MockFiler_Mkdir_Call struct {
// Mkdir is a helper method to define mock.On call // Mkdir is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - path string // - path string
func (_e *MockFiler_Expecter) Mkdir(ctx interface{}, path interface{}) *MockFiler_Mkdir_Call { func (_e *MockFiler_Expecter) Mkdir(ctx any, path any) *MockFiler_Mkdir_Call {
return &MockFiler_Mkdir_Call{Call: _e.mock.On("Mkdir", ctx, path)} return &MockFiler_Mkdir_Call{Call: _e.mock.On("Mkdir", ctx, path)}
} }
@ -173,7 +173,7 @@ type MockFiler_Read_Call struct {
// Read is a helper method to define mock.On call // Read is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - path string // - path string
func (_e *MockFiler_Expecter) Read(ctx interface{}, path interface{}) *MockFiler_Read_Call { func (_e *MockFiler_Expecter) Read(ctx any, path any) *MockFiler_Read_Call {
return &MockFiler_Read_Call{Call: _e.mock.On("Read", ctx, path)} return &MockFiler_Read_Call{Call: _e.mock.On("Read", ctx, path)}
} }
@ -232,7 +232,7 @@ type MockFiler_ReadDir_Call struct {
// ReadDir is a helper method to define mock.On call // ReadDir is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - path string // - path string
func (_e *MockFiler_Expecter) ReadDir(ctx interface{}, path interface{}) *MockFiler_ReadDir_Call { func (_e *MockFiler_Expecter) ReadDir(ctx any, path any) *MockFiler_ReadDir_Call {
return &MockFiler_ReadDir_Call{Call: _e.mock.On("ReadDir", ctx, path)} return &MockFiler_ReadDir_Call{Call: _e.mock.On("ReadDir", ctx, path)}
} }
@ -291,7 +291,7 @@ type MockFiler_Stat_Call struct {
// Stat is a helper method to define mock.On call // Stat is a helper method to define mock.On call
// - ctx context.Context // - ctx context.Context
// - name string // - name string
func (_e *MockFiler_Expecter) Stat(ctx interface{}, name interface{}) *MockFiler_Stat_Call { func (_e *MockFiler_Expecter) Stat(ctx any, name any) *MockFiler_Stat_Call {
return &MockFiler_Stat_Call{Call: _e.mock.On("Stat", ctx, name)} return &MockFiler_Stat_Call{Call: _e.mock.On("Stat", ctx, name)}
} }
@ -314,11 +314,11 @@ func (_c *MockFiler_Stat_Call) RunAndReturn(run func(context.Context, string) (f
// Write provides a mock function with given fields: ctx, path, reader, mode // Write provides a mock function with given fields: ctx, path, reader, mode
func (_m *MockFiler) Write(ctx context.Context, path string, reader io.Reader, mode ...filer.WriteMode) error { func (_m *MockFiler) Write(ctx context.Context, path string, reader io.Reader, mode ...filer.WriteMode) error {
_va := make([]interface{}, len(mode)) _va := make([]any, len(mode))
for _i := range mode { for _i := range mode {
_va[_i] = mode[_i] _va[_i] = mode[_i]
} }
var _ca []interface{} var _ca []any
_ca = append(_ca, ctx, path, reader) _ca = append(_ca, ctx, path, reader)
_ca = append(_ca, _va...) _ca = append(_ca, _va...)
ret := _m.Called(_ca...) ret := _m.Called(_ca...)
@ -347,9 +347,9 @@ type MockFiler_Write_Call struct {
// - path string // - path string
// - reader io.Reader // - reader io.Reader
// - mode ...filer.WriteMode // - mode ...filer.WriteMode
func (_e *MockFiler_Expecter) Write(ctx interface{}, path interface{}, reader interface{}, mode ...interface{}) *MockFiler_Write_Call { func (_e *MockFiler_Expecter) Write(ctx any, path any, reader any, mode ...any) *MockFiler_Write_Call {
return &MockFiler_Write_Call{Call: _e.mock.On("Write", return &MockFiler_Write_Call{Call: _e.mock.On("Write",
append([]interface{}{ctx, path, reader}, mode...)...)} append([]any{ctx, path, reader}, mode...)...)}
} }
func (_c *MockFiler_Write_Call) Run(run func(ctx context.Context, path string, reader io.Reader, mode ...filer.WriteMode)) *MockFiler_Write_Call { func (_c *MockFiler_Write_Call) Run(run func(ctx context.Context, path string, reader io.Reader, mode ...filer.WriteMode)) *MockFiler_Write_Call {

View File

@ -100,7 +100,7 @@ func trimRightSpace(s string) string {
} }
// tmpl executes the given template text on data, writing the result to w. // tmpl executes the given template text on data, writing the result to w.
func tmpl(w io.Writer, text string, data interface{}) error { func tmpl(w io.Writer, text string, data any) error {
t := template.New("top") t := template.New("top")
t.Funcs(templateFuncs) t.Funcs(templateFuncs)
template.Must(t.Parse(text)) template.Must(t.Parse(text))

View File

@ -297,10 +297,10 @@ var renderFuncMap = template.FuncMap{
"yellow": color.YellowString, "yellow": color.YellowString,
"magenta": color.MagentaString, "magenta": color.MagentaString,
"cyan": color.CyanString, "cyan": color.CyanString,
"bold": func(format string, a ...interface{}) string { "bold": func(format string, a ...any) string {
return color.New(color.Bold).Sprintf(format, a...) return color.New(color.Bold).Sprintf(format, a...)
}, },
"italic": func(format string, a ...interface{}) string { "italic": func(format string, a ...any) string {
return color.New(color.Italic).Sprintf(format, a...) return color.New(color.Italic).Sprintf(format, a...)
}, },
"replace": strings.ReplaceAll, "replace": strings.ReplaceAll,

View File

@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func Equal(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { func Equal(t assert.TestingT, expected any, actual any, msgAndArgs ...any) bool {
ev, eok := expected.(dyn.Value) ev, eok := expected.(dyn.Value)
av, aok := actual.(dyn.Value) av, aok := actual.(dyn.Value)
if eok && aok && ev.IsValid() && av.IsValid() { if eok && aok && ev.IsValid() && av.IsValid() {
@ -32,86 +32,86 @@ func Equal(t assert.TestingT, expected interface{}, actual interface{}, msgAndAr
return assert.Equal(t, expected, actual, msgAndArgs...) return assert.Equal(t, expected, actual, msgAndArgs...)
} }
func EqualValues(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { func EqualValues(t assert.TestingT, expected, actual any, msgAndArgs ...any) bool {
return assert.EqualValues(t, expected, actual, msgAndArgs...) return assert.EqualValues(t, expected, actual, msgAndArgs...)
} }
func NotEqual(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { func NotEqual(t assert.TestingT, expected any, actual any, msgAndArgs ...any) bool {
return assert.NotEqual(t, expected, actual, msgAndArgs...) return assert.NotEqual(t, expected, actual, msgAndArgs...)
} }
func Len(t assert.TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool { func Len(t assert.TestingT, object any, length int, msgAndArgs ...any) bool {
return assert.Len(t, object, length, msgAndArgs...) return assert.Len(t, object, length, msgAndArgs...)
} }
func Empty(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { func Empty(t assert.TestingT, object any, msgAndArgs ...any) bool {
return assert.Empty(t, object, msgAndArgs...) return assert.Empty(t, object, msgAndArgs...)
} }
func Nil(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { func Nil(t assert.TestingT, object any, msgAndArgs ...any) bool {
return assert.Nil(t, object, msgAndArgs...) return assert.Nil(t, object, msgAndArgs...)
} }
func NotNil(t assert.TestingT, object interface{}, msgAndArgs ...interface{}) bool { func NotNil(t assert.TestingT, object any, msgAndArgs ...any) bool {
return assert.NotNil(t, object, msgAndArgs...) return assert.NotNil(t, object, msgAndArgs...)
} }
func NoError(t assert.TestingT, err error, msgAndArgs ...interface{}) bool { func NoError(t assert.TestingT, err error, msgAndArgs ...any) bool {
return assert.NoError(t, err, msgAndArgs...) return assert.NoError(t, err, msgAndArgs...)
} }
func Error(t assert.TestingT, err error, msgAndArgs ...interface{}) bool { func Error(t assert.TestingT, err error, msgAndArgs ...any) bool {
return assert.Error(t, err, msgAndArgs...) return assert.Error(t, err, msgAndArgs...)
} }
func EqualError(t assert.TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { func EqualError(t assert.TestingT, theError error, errString string, msgAndArgs ...any) bool {
return assert.EqualError(t, theError, errString, msgAndArgs...) return assert.EqualError(t, theError, errString, msgAndArgs...)
} }
func ErrorContains(t assert.TestingT, theError error, contains string, msgAndArgs ...interface{}) bool { func ErrorContains(t assert.TestingT, theError error, contains string, msgAndArgs ...any) bool {
return assert.ErrorContains(t, theError, contains, msgAndArgs...) return assert.ErrorContains(t, theError, contains, msgAndArgs...)
} }
func ErrorIs(t assert.TestingT, theError, target error, msgAndArgs ...interface{}) bool { func ErrorIs(t assert.TestingT, theError, target error, msgAndArgs ...any) bool {
return assert.ErrorIs(t, theError, target, msgAndArgs...) return assert.ErrorIs(t, theError, target, msgAndArgs...)
} }
func True(t assert.TestingT, value bool, msgAndArgs ...interface{}) bool { func True(t assert.TestingT, value bool, msgAndArgs ...any) bool {
return assert.True(t, value, msgAndArgs...) return assert.True(t, value, msgAndArgs...)
} }
func False(t assert.TestingT, value bool, msgAndArgs ...interface{}) bool { func False(t assert.TestingT, value bool, msgAndArgs ...any) bool {
return assert.False(t, value, msgAndArgs...) return assert.False(t, value, msgAndArgs...)
} }
func Contains(t assert.TestingT, list interface{}, element interface{}, msgAndArgs ...interface{}) bool { func Contains(t assert.TestingT, list any, element any, msgAndArgs ...any) bool {
return assert.Contains(t, list, element, msgAndArgs...) return assert.Contains(t, list, element, msgAndArgs...)
} }
func NotContains(t assert.TestingT, list interface{}, element interface{}, msgAndArgs ...interface{}) bool { func NotContains(t assert.TestingT, list any, element any, msgAndArgs ...any) bool {
return assert.NotContains(t, list, element, msgAndArgs...) return assert.NotContains(t, list, element, msgAndArgs...)
} }
func ElementsMatch(t assert.TestingT, listA, listB interface{}, msgAndArgs ...interface{}) bool { func ElementsMatch(t assert.TestingT, listA, listB any, msgAndArgs ...any) bool {
return assert.ElementsMatch(t, listA, listB, msgAndArgs...) return assert.ElementsMatch(t, listA, listB, msgAndArgs...)
} }
func Panics(t assert.TestingT, f func(), msgAndArgs ...interface{}) bool { func Panics(t assert.TestingT, f func(), msgAndArgs ...any) bool {
return assert.Panics(t, f, msgAndArgs...) return assert.Panics(t, f, msgAndArgs...)
} }
func PanicsWithValue(t assert.TestingT, expected interface{}, f func(), msgAndArgs ...interface{}) bool { func PanicsWithValue(t assert.TestingT, expected any, f func(), msgAndArgs ...any) bool {
return assert.PanicsWithValue(t, expected, f, msgAndArgs...) return assert.PanicsWithValue(t, expected, f, msgAndArgs...)
} }
func PanicsWithError(t assert.TestingT, errString string, f func(), msgAndArgs ...interface{}) bool { func PanicsWithError(t assert.TestingT, errString string, f func(), msgAndArgs ...any) bool {
return assert.PanicsWithError(t, errString, f, msgAndArgs...) return assert.PanicsWithError(t, errString, f, msgAndArgs...)
} }
func NotPanics(t assert.TestingT, f func(), msgAndArgs ...interface{}) bool { func NotPanics(t assert.TestingT, f func(), msgAndArgs ...any) bool {
return assert.NotPanics(t, f, msgAndArgs...) return assert.NotPanics(t, f, msgAndArgs...)
} }
func JSONEq(t assert.TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { func JSONEq(t assert.TestingT, expected string, actual string, msgAndArgs ...any) bool {
return assert.JSONEq(t, expected, actual, msgAndArgs...) return assert.JSONEq(t, expected, actual, msgAndArgs...)
} }

View File

@ -14,7 +14,7 @@ type loader struct {
path string path string
} }
func errorf(loc dyn.Location, format string, args ...interface{}) error { func errorf(loc dyn.Location, format string, args ...any) error {
return fmt.Errorf("yaml (%s): %s", loc, fmt.Sprintf(format, args...)) return fmt.Errorf("yaml (%s): %s", loc, fmt.Sprintf(format, args...))
} }

View File

@ -59,7 +59,7 @@ func (ec errorChain) Unwrap() error {
return ec[1:] return ec[1:]
} }
func (ec errorChain) As(target interface{}) bool { func (ec errorChain) As(target any) bool {
return errors.As(ec[0], target) return errors.As(ec[0], target)
} }

View File

@ -11,10 +11,10 @@ import (
func TestFromTypeBasic(t *testing.T) { func TestFromTypeBasic(t *testing.T) {
type myStruct struct { type myStruct struct {
S string `json:"s"` S string `json:"s"`
I *int `json:"i,omitempty"` I *int `json:"i,omitempty"`
V interface{} `json:"v,omitempty"` V any `json:"v,omitempty"`
TriplePointer ***int `json:"triple_pointer,omitempty"` TriplePointer ***int `json:"triple_pointer,omitempty"`
// These fields should be ignored in the resulting schema. // These fields should be ignored in the resulting schema.
NotAnnotated string NotAnnotated string