Skip to content

Commit 3c5408e

Browse files
authored
chore: Use any instead of interface{} (#3584)
1 parent b52ed30 commit 3c5408e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+332
-210
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ linters-settings:
106106
- name: unexported-naming
107107
- name: unexported-return
108108
- name: unreachable-code
109+
- name: use-any
109110
- name: var-declaration
110111
- name: var-naming
111112
issues:

github/actions_secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type PublicKey struct {
2323
// do not error out when unmarshaling.
2424
func (p *PublicKey) UnmarshalJSON(data []byte) error {
2525
var pk struct {
26-
KeyID interface{} `json:"key_id"`
27-
Key *string `json:"key"`
26+
KeyID any `json:"key_id"`
27+
Key *string `json:"key"`
2828
}
2929

3030
if err := json.Unmarshal(data, &pk); err != nil {

github/actions_workflows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type CreateWorkflowDispatchEventRequest struct {
5353
// Inputs represents input keys and values configured in the workflow file.
5454
// The maximum number of properties is 10.
5555
// Default: Any default properties configured in the workflow file will be used when `inputs` are omitted.
56-
Inputs map[string]interface{} `json:"inputs,omitempty"`
56+
Inputs map[string]any `json:"inputs,omitempty"`
5757
}
5858

5959
// ListWorkflows lists all workflows in a repository.

github/actions_workflows_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
237237

238238
event := CreateWorkflowDispatchEventRequest{
239239
Ref: "d4cfb6e7",
240-
Inputs: map[string]interface{}{
240+
Inputs: map[string]any{
241241
"key": "value",
242242
},
243243
}
@@ -281,7 +281,7 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {
281281

282282
event := CreateWorkflowDispatchEventRequest{
283283
Ref: "d4cfb6e7",
284-
Inputs: map[string]interface{}{
284+
Inputs: map[string]any{
285285
"key": "value",
286286
},
287287
}
@@ -618,7 +618,7 @@ func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) {
618618
t.Parallel()
619619
testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}")
620620

621-
inputs := make(map[string]interface{}, 0)
621+
inputs := make(map[string]any, 0)
622622
inputs["key"] = "value"
623623

624624
u := &CreateWorkflowDispatchEventRequest{

github/activity_events_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func TestActivityService_EventParsePayload_typed(t *testing.T) {
437437
}
438438

439439
// TestEvent_Payload_untyped checks that unrecognized events are parsed to an
440-
// interface{} value (instead of being discarded or throwing an error), for
440+
// any value (instead of being discarded or throwing an error), for
441441
// forward compatibility with new event types.
442442
func TestActivityService_EventParsePayload_untyped(t *testing.T) {
443443
t.Parallel()
@@ -447,7 +447,7 @@ func TestActivityService_EventParsePayload_untyped(t *testing.T) {
447447
t.Fatalf("Unmarshal Event returned error: %v", err)
448448
}
449449

450-
want := map[string]interface{}{"field": "val"}
450+
want := map[string]any{"field": "val"}
451451
got, err := event.ParsePayload()
452452
if err != nil {
453453
t.Fatalf("ParsePayload returned unexpected error: %v", err)

github/copilot.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ type ListCopilotSeatsResponse struct {
4646
// CopilotSeatDetails represents the details of a Copilot for Business seat.
4747
type CopilotSeatDetails struct {
4848
// Assignee can either be a User, Team, or Organization.
49-
Assignee interface{} `json:"assignee"`
50-
AssigningTeam *Team `json:"assigning_team,omitempty"`
51-
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
52-
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
53-
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
54-
CreatedAt *Timestamp `json:"created_at"`
55-
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
56-
PlanType *string `json:"plan_type,omitempty"`
49+
Assignee any `json:"assignee"`
50+
AssigningTeam *Team `json:"assigning_team,omitempty"`
51+
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
52+
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
53+
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
54+
CreatedAt *Timestamp `json:"created_at"`
55+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
56+
PlanType *string `json:"plan_type,omitempty"`
5757
}
5858

5959
// SeatAssignments represents the number of seats assigned.
@@ -203,7 +203,7 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error {
203203
cp.PlanType = seatDetail.PlanType
204204

205205
switch v := seatDetail.Assignee.(type) {
206-
case map[string]interface{}:
206+
case map[string]any:
207207
jsonData, err := json.Marshal(seatDetail.Assignee)
208208
if err != nil {
209209
return err

github/enterprise_audit_log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) {
6161
Actor: Ptr("testactor"),
6262
CreatedAt: &Timestamp{timestamp},
6363
Org: Ptr("o"),
64-
AdditionalFields: map[string]interface{}{
64+
AdditionalFields: map[string]any{
6565
"completed_at": "2021-03-07T00:35:08.000Z",
6666
"conclusion": "success",
6767
"event": "schedule",

github/event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (e Event) String() string {
2727

2828
// ParsePayload parses the event payload. For recognized event types,
2929
// a value of the corresponding struct type will be returned.
30-
func (e *Event) ParsePayload() (interface{}, error) {
30+
func (e *Event) ParsePayload() (any, error) {
3131
// It would be nice if e.Type were the snake_case name of the event,
3232
// but the existing interface uses the struct name instead.
3333
payload := EventForType(typeToMessageMapping[e.GetType()])
@@ -44,7 +44,7 @@ func (e *Event) ParsePayload() (interface{}, error) {
4444
//
4545
// Deprecated: Use ParsePayload instead, which returns an error
4646
// rather than panics if JSON unmarshaling raw payload fails.
47-
func (e *Event) Payload() (payload interface{}) {
47+
func (e *Event) Payload() (payload any) {
4848
var err error
4949
payload, err = e.ParsePayload()
5050
if err != nil {

github/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestEvent_Marshal(t *testing.T) {
4949
t.Parallel()
5050
testJSONMarshal(t, &Event{}, "{}")
5151

52-
l := make(map[string]interface{})
52+
l := make(map[string]any)
5353
l["key"] = "value"
5454

5555
jsonMsg, _ := json.Marshal(&l)

github/event_types.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,44 +1400,44 @@ func (h HeadCommit) String() string {
14001400

14011401
// PushEventRepository represents the repo object in a PushEvent payload.
14021402
type PushEventRepository struct {
1403-
ID *int64 `json:"id,omitempty"`
1404-
NodeID *string `json:"node_id,omitempty"`
1405-
Name *string `json:"name,omitempty"`
1406-
FullName *string `json:"full_name,omitempty"`
1407-
Owner *User `json:"owner,omitempty"`
1408-
Private *bool `json:"private,omitempty"`
1409-
Description *string `json:"description,omitempty"`
1410-
Fork *bool `json:"fork,omitempty"`
1411-
CreatedAt *Timestamp `json:"created_at,omitempty"`
1412-
PushedAt *Timestamp `json:"pushed_at,omitempty"`
1413-
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
1414-
Homepage *string `json:"homepage,omitempty"`
1415-
PullsURL *string `json:"pulls_url,omitempty"`
1416-
Size *int `json:"size,omitempty"`
1417-
StargazersCount *int `json:"stargazers_count,omitempty"`
1418-
WatchersCount *int `json:"watchers_count,omitempty"`
1419-
Language *string `json:"language,omitempty"`
1420-
HasIssues *bool `json:"has_issues,omitempty"`
1421-
HasDownloads *bool `json:"has_downloads,omitempty"`
1422-
HasWiki *bool `json:"has_wiki,omitempty"`
1423-
HasPages *bool `json:"has_pages,omitempty"`
1424-
ForksCount *int `json:"forks_count,omitempty"`
1425-
Archived *bool `json:"archived,omitempty"`
1426-
Disabled *bool `json:"disabled,omitempty"`
1427-
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
1428-
DefaultBranch *string `json:"default_branch,omitempty"`
1429-
MasterBranch *string `json:"master_branch,omitempty"`
1430-
Organization *string `json:"organization,omitempty"`
1431-
URL *string `json:"url,omitempty"`
1432-
ArchiveURL *string `json:"archive_url,omitempty"`
1433-
HTMLURL *string `json:"html_url,omitempty"`
1434-
StatusesURL *string `json:"statuses_url,omitempty"`
1435-
GitURL *string `json:"git_url,omitempty"`
1436-
SSHURL *string `json:"ssh_url,omitempty"`
1437-
CloneURL *string `json:"clone_url,omitempty"`
1438-
SVNURL *string `json:"svn_url,omitempty"`
1439-
Topics []string `json:"topics,omitempty"`
1440-
CustomProperties map[string]interface{} `json:"custom_properties,omitempty"`
1403+
ID *int64 `json:"id,omitempty"`
1404+
NodeID *string `json:"node_id,omitempty"`
1405+
Name *string `json:"name,omitempty"`
1406+
FullName *string `json:"full_name,omitempty"`
1407+
Owner *User `json:"owner,omitempty"`
1408+
Private *bool `json:"private,omitempty"`
1409+
Description *string `json:"description,omitempty"`
1410+
Fork *bool `json:"fork,omitempty"`
1411+
CreatedAt *Timestamp `json:"created_at,omitempty"`
1412+
PushedAt *Timestamp `json:"pushed_at,omitempty"`
1413+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
1414+
Homepage *string `json:"homepage,omitempty"`
1415+
PullsURL *string `json:"pulls_url,omitempty"`
1416+
Size *int `json:"size,omitempty"`
1417+
StargazersCount *int `json:"stargazers_count,omitempty"`
1418+
WatchersCount *int `json:"watchers_count,omitempty"`
1419+
Language *string `json:"language,omitempty"`
1420+
HasIssues *bool `json:"has_issues,omitempty"`
1421+
HasDownloads *bool `json:"has_downloads,omitempty"`
1422+
HasWiki *bool `json:"has_wiki,omitempty"`
1423+
HasPages *bool `json:"has_pages,omitempty"`
1424+
ForksCount *int `json:"forks_count,omitempty"`
1425+
Archived *bool `json:"archived,omitempty"`
1426+
Disabled *bool `json:"disabled,omitempty"`
1427+
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
1428+
DefaultBranch *string `json:"default_branch,omitempty"`
1429+
MasterBranch *string `json:"master_branch,omitempty"`
1430+
Organization *string `json:"organization,omitempty"`
1431+
URL *string `json:"url,omitempty"`
1432+
ArchiveURL *string `json:"archive_url,omitempty"`
1433+
HTMLURL *string `json:"html_url,omitempty"`
1434+
StatusesURL *string `json:"statuses_url,omitempty"`
1435+
GitURL *string `json:"git_url,omitempty"`
1436+
SSHURL *string `json:"ssh_url,omitempty"`
1437+
CloneURL *string `json:"clone_url,omitempty"`
1438+
SVNURL *string `json:"svn_url,omitempty"`
1439+
Topics []string `json:"topics,omitempty"`
1440+
CustomProperties map[string]any `json:"custom_properties,omitempty"`
14411441
}
14421442

14431443
// PushEventRepoOwner is a basic representation of user/org in a PushEvent payload.

github/event_types_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5644,7 +5644,7 @@ func TestDeploymentEvent_Marshal(t *testing.T) {
56445644
t.Parallel()
56455645
testJSONMarshal(t, &DeploymentEvent{}, "{}")
56465646

5647-
l := make(map[string]interface{})
5647+
l := make(map[string]any)
56485648
l["key"] = "value"
56495649

56505650
jsonMsg, _ := json.Marshal(&l)
@@ -6114,7 +6114,7 @@ func TestDeploymentProtectionRuleEvent_Marshal(t *testing.T) {
61146114
t.Parallel()
61156115
testJSONMarshal(t, &DeploymentProtectionRuleEvent{}, "{}")
61166116

6117-
l := make(map[string]interface{})
6117+
l := make(map[string]any)
61186118
l["key"] = "value"
61196119

61206120
jsonMsg, _ := json.Marshal(&l)
@@ -7099,7 +7099,7 @@ func TestDeploymentStatusEvent_Marshal(t *testing.T) {
70997099
t.Parallel()
71007100
testJSONMarshal(t, &DeploymentStatusEvent{}, "{}")
71017101

7102-
l := make(map[string]interface{})
7102+
l := make(map[string]any)
71037103
l["key"] = "value"
71047104

71057105
jsonMsg, _ := json.Marshal(&l)
@@ -8399,7 +8399,7 @@ func TestPingEvent_Marshal(t *testing.T) {
83998399
t.Parallel()
84008400
testJSONMarshal(t, &PingEvent{}, "{}")
84018401

8402-
l := make(map[string]interface{})
8402+
l := make(map[string]any)
84038403
l["key"] = "value"
84048404
hookConfig := new(HookConfig)
84058405

@@ -8773,7 +8773,7 @@ func TestRepositoryDispatchEvent_Marshal(t *testing.T) {
87738773
t.Parallel()
87748774
testJSONMarshal(t, &RepositoryDispatchEvent{}, "{}")
87758775

8776-
l := make(map[string]interface{})
8776+
l := make(map[string]any)
87778777
l["key"] = "value"
87788778

87798779
jsonMsg, _ := json.Marshal(&l)
@@ -11978,7 +11978,7 @@ func TestWorkflowDispatchEvent_Marshal(t *testing.T) {
1197811978
t.Parallel()
1197911979
testJSONMarshal(t, &WorkflowDispatchEvent{}, "{}")
1198011980

11981-
i := make(map[string]interface{})
11981+
i := make(map[string]any)
1198211982
i["key"] = "value"
1198311983

1198411984
jsonMsg, _ := json.Marshal(i)
@@ -13343,7 +13343,7 @@ func TestMetaEvent_Marshal(t *testing.T) {
1334313343
t.Parallel()
1334413344
testJSONMarshal(t, &MetaEvent{}, "{}")
1334513345

13346-
v := make(map[string]interface{})
13346+
v := make(map[string]any)
1334713347
v["a"] = "b"
1334813348
hookConfig := &HookConfig{
1334913349
ContentType: Ptr("json"),

github/gen-accessors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var (
5959
}
6060
)
6161

62-
func logf(fmt string, args ...interface{}) {
62+
func logf(fmt string, args ...any) {
6363
if *verbose {
6464
log.Printf(fmt, args...)
6565
}

github/gen-stringify-test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ var (
7272
return `[""]`
7373
case "[]Scope{ScopeNone}":
7474
return `["(no scope)"]`
75+
case "[]any{nil}":
76+
return "[<nil>]"
7577
}
7678
log.Fatalf("Unhandled zero value: %q", v)
7779
return ""
@@ -311,6 +313,8 @@ func (t *templateData) addIdentSlice(x *ast.Ident, receiverType, fieldName strin
311313
zeroValue = "[]bool{false}"
312314
case "Scope":
313315
zeroValue = "[]Scope{ScopeNone}"
316+
case "any":
317+
zeroValue = "[]any{nil}"
314318
// case "Timestamp":
315319
// zeroValue = "&Timestamp{}"
316320
default:
@@ -377,7 +381,7 @@ func newStructField(receiverType, fieldName, fieldType, zeroValue string, namedS
377381
}
378382
}
379383

380-
func logf(fmt string, args ...interface{}) {
384+
func logf(fmt string, args ...any) {
381385
if *verbose {
382386
log.Printf(fmt, args...)
383387
}

github/git_trees.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha
118118

119119
// createTree represents the body of a CreateTree request.
120120
type createTree struct {
121-
BaseTree string `json:"base_tree,omitempty"`
122-
Entries []interface{} `json:"tree"`
121+
BaseTree string `json:"base_tree,omitempty"`
122+
Entries []any `json:"tree"`
123123
}
124124

125125
// CreateTree creates a new tree in a repository. If both a tree and a nested
@@ -132,7 +132,7 @@ type createTree struct {
132132
func (s *GitService) CreateTree(ctx context.Context, owner string, repo string, baseTree string, entries []*TreeEntry) (*Tree, *Response, error) {
133133
u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo)
134134

135-
newEntries := make([]interface{}, 0, len(entries))
135+
newEntries := make([]any, 0, len(entries))
136136
for _, entry := range entries {
137137
if entry.Content == nil && entry.SHA == nil {
138138
newEntries = append(newEntries, treeEntryWithFileDelete{

github/git_trees_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func TestCreateTree_Marshal(t *testing.T) {
441441

442442
u := &createTree{
443443
BaseTree: "bt",
444-
Entries: []interface{}{"e"},
444+
Entries: []any{"e"},
445445
}
446446

447447
want := `{

0 commit comments

Comments
 (0)