From ce3ecacbe2948aae6fec16e7bd6c6f6007068c0f Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Tue, 27 Jun 2023 13:34:30 -0700 Subject: [PATCH] Add lint rule to use any instead of interface{} (#3685) #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [x] :broom: Tech Debt/Cleanup #### Issue(s) * #3654 #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/.golangci.yml | 1 + src/internal/m365/graph/metadata/metadata_test.go | 2 +- src/internal/m365/onedrive/collections_test.go | 2 +- src/internal/m365/onedrive/item_test.go | 10 +++++----- src/internal/m365/onedrive/restore.go | 2 +- src/internal/m365/sharepoint/mock/list.go | 2 +- src/pkg/services/m365/api/events.go | 2 +- src/pkg/services/m365/api/mail_test.go | 4 ++-- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/.golangci.yml b/src/.golangci.yml index 0949053cc..06ccaa3dd 100644 --- a/src/.golangci.yml +++ b/src/.golangci.yml @@ -81,6 +81,7 @@ linters-settings: - name: time-equal - name: time-naming - name: unreachable-code + - name: use-any - name: useless-break - name: var-declaration - name: var-naming diff --git a/src/internal/m365/graph/metadata/metadata_test.go b/src/internal/m365/graph/metadata/metadata_test.go index 6501c667c..f7c1b81fe 100644 --- a/src/internal/m365/graph/metadata/metadata_test.go +++ b/src/internal/m365/graph/metadata/metadata_test.go @@ -15,7 +15,7 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -type boolfAssertionFunc func(assert.TestingT, bool, string, ...interface{}) bool +type boolfAssertionFunc func(assert.TestingT, bool, string, ...any) bool type testCase struct { service path.ServiceType diff --git a/src/internal/m365/onedrive/collections_test.go b/src/internal/m365/onedrive/collections_test.go index e7cc68849..72cdf9585 100644 --- a/src/internal/m365/onedrive/collections_test.go +++ b/src/internal/m365/onedrive/collections_test.go @@ -2497,7 +2497,7 @@ func fileItem( deleted bool, ) models.DriveItemable { di := driveItem(id, name, parentPath, parentID, true, false, false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@microsoft.graph.downloadUrl": url, }) diff --git a/src/internal/m365/onedrive/item_test.go b/src/internal/m365/onedrive/item_test.go index c579cb27a..2b3b80453 100644 --- a/src/internal/m365/onedrive/item_test.go +++ b/src/internal/m365/onedrive/item_test.go @@ -315,7 +315,7 @@ func (suite *ItemUnitTestSuite) TestDownloadItem() { name: "success", itemFunc: func() models.DriveItemable { di := newItem("test", false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@microsoft.graph.downloadUrl": url, }) @@ -334,7 +334,7 @@ func (suite *ItemUnitTestSuite) TestDownloadItem() { name: "success, content url set instead of download url", itemFunc: func() models.DriveItemable { di := newItem("test", false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@content.downloadUrl": url, }) @@ -353,7 +353,7 @@ func (suite *ItemUnitTestSuite) TestDownloadItem() { name: "api getter returns error", itemFunc: func() models.DriveItemable { di := newItem("test", false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@microsoft.graph.downloadUrl": url, }) @@ -384,7 +384,7 @@ func (suite *ItemUnitTestSuite) TestDownloadItem() { name: "malware", itemFunc: func() models.DriveItemable { di := newItem("test", false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@microsoft.graph.downloadUrl": url, }) @@ -406,7 +406,7 @@ func (suite *ItemUnitTestSuite) TestDownloadItem() { name: "non-2xx http response", itemFunc: func() models.DriveItemable { di := newItem("test", false) - di.SetAdditionalData(map[string]interface{}{ + di.SetAdditionalData(map[string]any{ "@microsoft.graph.downloadUrl": url, }) diff --git a/src/internal/m365/onedrive/restore.go b/src/internal/m365/onedrive/restore.go index 0edbaf62a..e0031c485 100644 --- a/src/internal/m365/onedrive/restore.go +++ b/src/internal/m365/onedrive/restore.go @@ -51,7 +51,7 @@ func NewRestoreCaches() *restoreCaches { DriveIDToRootFolderID: map[string]string{}, // Buffer pool for uploads pool: sync.Pool{ - New: func() interface{} { + New: func() any { b := make([]byte, graph.CopyBufferSize) return &b }, diff --git a/src/internal/m365/sharepoint/mock/list.go b/src/internal/m365/sharepoint/mock/list.go index 885940233..4990495d5 100644 --- a/src/internal/m365/sharepoint/mock/list.go +++ b/src/internal/m365/sharepoint/mock/list.go @@ -116,7 +116,7 @@ func List(title, columnName string, items map[string]string) models.Listable { itms := make([]models.ListItemable, 0) for k, v := range items { - entry := map[string]interface{}{ + entry := map[string]any{ "Title": k, columnName: v, } diff --git a/src/pkg/services/m365/api/events.go b/src/pkg/services/m365/api/events.go index 4ed1b83b8..801f9abfa 100644 --- a/src/pkg/services/m365/api/events.go +++ b/src/pkg/services/m365/api/events.go @@ -302,7 +302,7 @@ func fixupExceptionOccurrences( // This odd roundabout way of doing this is required as // the json serialization at the end does not serialize if // you just pass in a models.Attachmentable - convertedAttachments := []map[string]interface{}{} + convertedAttachments := []map[string]any{} for _, attachment := range attachments { am, err := parseableToMap(attachment) diff --git a/src/pkg/services/m365/api/mail_test.go b/src/pkg/services/m365/api/mail_test.go index a328de9c1..e3a84e4bb 100644 --- a/src/pkg/services/m365/api/mail_test.go +++ b/src/pkg/services/m365/api/mail_test.go @@ -221,7 +221,7 @@ func (suite *MailAPIIntgSuite) SetupSuite() { suite.user = tester.M365UserID(t) } -func getJSONObject(t *testing.T, thing serialization.Parsable) map[string]interface{} { +func getJSONObject(t *testing.T, thing serialization.Parsable) map[string]any { sw := kjson.NewJsonSerializationWriter() err := sw.WriteObjectValue("", thing) @@ -230,7 +230,7 @@ func getJSONObject(t *testing.T, thing serialization.Parsable) map[string]interf content, err := sw.GetSerializedContent() require.NoError(t, err, "serialize") - var out map[string]interface{} + var out map[string]any err = json.Unmarshal([]byte(content), &out) require.NoError(t, err, "unmarshall")