Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite 'interface{} -> any' #1959

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ linters-settings:
rewrite-rules:
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
- pattern: 'interface{}'
replacement: 'any'
issues:
exclude-dirs-use-default: false # recommended by docs https://golangci-lint.run/usage/false-positives/
6 changes: 3 additions & 3 deletions bundle/config/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
"complex": {
Type: variable.VariableTypeComplex,
Description: "complex var",
Default: map[string]interface{}{
Default: map[string]any{
"key": "value",
},
},
Expand All @@ -148,7 +148,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
"complex": {
Type: "wrong",
Description: "wrong",
Default: map[string]interface{}{
Default: map[string]any{
"key1": "value1",
},
},
Expand All @@ -164,7 +164,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
assert.Equal(t, "foo2", root.Variables["foo2"].Default)
assert.Equal(t, "foo2 var", root.Variables["foo2"].Description)

assert.Equal(t, map[string]interface{}{
assert.Equal(t, map[string]any{
"key1": "value1",
}, root.Variables["complex"].Default)
assert.Equal(t, "complex var", root.Variables["complex"].Description)
Expand Down
8 changes: 4 additions & 4 deletions bundle/internal/tf/codegen/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

func (s *Schema) writeTerraformBlock(_ context.Context) error {
var body = map[string]interface{}{
"terraform": map[string]interface{}{
"required_providers": map[string]interface{}{
"databricks": map[string]interface{}{
var body = map[string]any{
"terraform": map[string]any{
"required_providers": map[string]any{
"databricks": map[string]any{
"source": "databricks/databricks",
"version": ProviderVersion,
},
Expand Down
6 changes: 3 additions & 3 deletions bundle/internal/tf/schema/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const ProviderVersion = "1.58.0"

func NewRoot() *Root {
return &Root{
Terraform: map[string]interface{}{
"required_providers": map[string]interface{}{
"databricks": map[string]interface{}{
Terraform: map[string]any{
"required_providers": map[string]any{
"databricks": map[string]any{
"source": ProviderSource,
"version": ProviderVersion,
},
Expand Down
4 changes: 2 additions & 2 deletions bundle/render/render_text_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var renderFuncMap = template.FuncMap{
"yellow": color.YellowString,
"magenta": color.MagentaString,
"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...)
},
"italic": func(format string, a ...interface{}) string {
"italic": func(format string, a ...any) string {
return color.New(color.Italic).Sprintf(format, a...)
},
}
Expand Down
2 changes: 1 addition & 1 deletion bundle/run/output/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type LogsOutput struct {
LogsTruncated bool `json:"logs_truncated"`
}

func structToString(val interface{}) (string, error) {
func structToString(val any) (string, error) {
b, err := json.MarshalIndent(val, "", " ")
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion bundle/tests/complex_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ func TestComplexVariablesOverrideWithFullSyntax(t *testing.T) {
require.Empty(t, diags)

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)
}
2 changes: 1 addition & 1 deletion internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (t *cobraTestRunner) Run() (bytes.Buffer, bytes.Buffer, error) {
}

// 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)

timer := time.NewTimer(waitFor)
Expand Down
24 changes: 12 additions & 12 deletions internal/mocks/libs/filer/mock_filer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/cmdgroup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func trimRightSpace(s string) string {
}

// 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.Funcs(templateFuncs)
template.Must(t.Parse(text))
Expand Down
4 changes: 2 additions & 2 deletions libs/cmdio/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ var renderFuncMap = template.FuncMap{
"yellow": color.YellowString,
"magenta": color.MagentaString,
"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...)
},
"italic": func(format string, a ...interface{}) string {
"italic": func(format string, a ...any) string {
return color.New(color.Italic).Sprintf(format, a...)
},
"replace": strings.ReplaceAll,
Expand Down
44 changes: 22 additions & 22 deletions libs/dyn/dynassert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"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)
av, aok := actual.(dyn.Value)
if eok && aok && ev.IsValid() && av.IsValid() {
Expand All @@ -32,86 +32,86 @@ func Equal(t assert.TestingT, expected interface{}, actual interface{}, msgAndAr
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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}

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...)
}
2 changes: 1 addition & 1 deletion libs/dyn/yamlloader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type loader struct {
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...))
}

Expand Down
2 changes: 1 addition & 1 deletion libs/errs/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (ec errorChain) Unwrap() error {
return ec[1:]
}

func (ec errorChain) As(target interface{}) bool {
func (ec errorChain) As(target any) bool {
return errors.As(ec[0], target)
}

Expand Down
8 changes: 4 additions & 4 deletions libs/jsonschema/from_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

func TestFromTypeBasic(t *testing.T) {
type myStruct struct {
S string `json:"s"`
I *int `json:"i,omitempty"`
V interface{} `json:"v,omitempty"`
TriplePointer ***int `json:"triple_pointer,omitempty"`
S string `json:"s"`
I *int `json:"i,omitempty"`
V any `json:"v,omitempty"`
TriplePointer ***int `json:"triple_pointer,omitempty"`

// These fields should be ignored in the resulting schema.
NotAnnotated string
Expand Down
Loading