Skip to content

chore: Use any instead of interface{} #3584

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

Merged
merged 1 commit into from
Jun 3, 2025
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ linters-settings:
- name: unexported-naming
- name: unexported-return
- name: unreachable-code
- name: use-any
- name: var-declaration
- name: var-naming
issues:
Expand Down
4 changes: 2 additions & 2 deletions github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type PublicKey struct {
// do not error out when unmarshaling.
func (p *PublicKey) UnmarshalJSON(data []byte) error {
var pk struct {
KeyID interface{} `json:"key_id"`
Key *string `json:"key"`
KeyID any `json:"key_id"`
Key *string `json:"key"`
}

if err := json.Unmarshal(data, &pk); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion github/actions_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type CreateWorkflowDispatchEventRequest struct {
// Inputs represents input keys and values configured in the workflow file.
// The maximum number of properties is 10.
// Default: Any default properties configured in the workflow file will be used when `inputs` are omitted.
Inputs map[string]interface{} `json:"inputs,omitempty"`
Inputs map[string]any `json:"inputs,omitempty"`
}

// ListWorkflows lists all workflows in a repository.
Expand Down
6 changes: 3 additions & 3 deletions github/actions_workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {

event := CreateWorkflowDispatchEventRequest{
Ref: "d4cfb6e7",
Inputs: map[string]interface{}{
Inputs: map[string]any{
"key": "value",
},
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {

event := CreateWorkflowDispatchEventRequest{
Ref: "d4cfb6e7",
Inputs: map[string]interface{}{
Inputs: map[string]any{
"key": "value",
},
}
Expand Down Expand Up @@ -618,7 +618,7 @@ func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}")

inputs := make(map[string]interface{}, 0)
inputs := make(map[string]any, 0)
inputs["key"] = "value"

u := &CreateWorkflowDispatchEventRequest{
Expand Down
4 changes: 2 additions & 2 deletions github/activity_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func TestActivityService_EventParsePayload_typed(t *testing.T) {
}

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

want := map[string]interface{}{"field": "val"}
want := map[string]any{"field": "val"}
got, err := event.ParsePayload()
if err != nil {
t.Fatalf("ParsePayload returned unexpected error: %v", err)
Expand Down
18 changes: 9 additions & 9 deletions github/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ type ListCopilotSeatsResponse struct {
// CopilotSeatDetails represents the details of a Copilot for Business seat.
type CopilotSeatDetails struct {
// Assignee can either be a User, Team, or Organization.
Assignee interface{} `json:"assignee"`
AssigningTeam *Team `json:"assigning_team,omitempty"`
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
CreatedAt *Timestamp `json:"created_at"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PlanType *string `json:"plan_type,omitempty"`
Assignee any `json:"assignee"`
AssigningTeam *Team `json:"assigning_team,omitempty"`
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
CreatedAt *Timestamp `json:"created_at"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
PlanType *string `json:"plan_type,omitempty"`
}

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

switch v := seatDetail.Assignee.(type) {
case map[string]interface{}:
case map[string]any:
jsonData, err := json.Marshal(seatDetail.Assignee)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion github/enterprise_audit_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) {
Actor: Ptr("testactor"),
CreatedAt: &Timestamp{timestamp},
Org: Ptr("o"),
AdditionalFields: map[string]interface{}{
AdditionalFields: map[string]any{
"completed_at": "2021-03-07T00:35:08.000Z",
"conclusion": "success",
"event": "schedule",
Expand Down
4 changes: 2 additions & 2 deletions github/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (e Event) String() string {

// ParsePayload parses the event payload. For recognized event types,
// a value of the corresponding struct type will be returned.
func (e *Event) ParsePayload() (interface{}, error) {
func (e *Event) ParsePayload() (any, error) {
// It would be nice if e.Type were the snake_case name of the event,
// but the existing interface uses the struct name instead.
payload := EventForType(typeToMessageMapping[e.GetType()])
Expand All @@ -44,7 +44,7 @@ func (e *Event) ParsePayload() (interface{}, error) {
//
// Deprecated: Use ParsePayload instead, which returns an error
// rather than panics if JSON unmarshaling raw payload fails.
func (e *Event) Payload() (payload interface{}) {
func (e *Event) Payload() (payload any) {
var err error
payload, err = e.ParsePayload()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion github/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &Event{}, "{}")

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"

jsonMsg, _ := json.Marshal(&l)
Expand Down
76 changes: 38 additions & 38 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1400,44 +1400,44 @@ func (h HeadCommit) String() string {

// PushEventRepository represents the repo object in a PushEvent payload.
type PushEventRepository struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
Owner *User `json:"owner,omitempty"`
Private *bool `json:"private,omitempty"`
Description *string `json:"description,omitempty"`
Fork *bool `json:"fork,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Homepage *string `json:"homepage,omitempty"`
PullsURL *string `json:"pulls_url,omitempty"`
Size *int `json:"size,omitempty"`
StargazersCount *int `json:"stargazers_count,omitempty"`
WatchersCount *int `json:"watchers_count,omitempty"`
Language *string `json:"language,omitempty"`
HasIssues *bool `json:"has_issues,omitempty"`
HasDownloads *bool `json:"has_downloads,omitempty"`
HasWiki *bool `json:"has_wiki,omitempty"`
HasPages *bool `json:"has_pages,omitempty"`
ForksCount *int `json:"forks_count,omitempty"`
Archived *bool `json:"archived,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
DefaultBranch *string `json:"default_branch,omitempty"`
MasterBranch *string `json:"master_branch,omitempty"`
Organization *string `json:"organization,omitempty"`
URL *string `json:"url,omitempty"`
ArchiveURL *string `json:"archive_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
StatusesURL *string `json:"statuses_url,omitempty"`
GitURL *string `json:"git_url,omitempty"`
SSHURL *string `json:"ssh_url,omitempty"`
CloneURL *string `json:"clone_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"`
Topics []string `json:"topics,omitempty"`
CustomProperties map[string]interface{} `json:"custom_properties,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
Owner *User `json:"owner,omitempty"`
Private *bool `json:"private,omitempty"`
Description *string `json:"description,omitempty"`
Fork *bool `json:"fork,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
Homepage *string `json:"homepage,omitempty"`
PullsURL *string `json:"pulls_url,omitempty"`
Size *int `json:"size,omitempty"`
StargazersCount *int `json:"stargazers_count,omitempty"`
WatchersCount *int `json:"watchers_count,omitempty"`
Language *string `json:"language,omitempty"`
HasIssues *bool `json:"has_issues,omitempty"`
HasDownloads *bool `json:"has_downloads,omitempty"`
HasWiki *bool `json:"has_wiki,omitempty"`
HasPages *bool `json:"has_pages,omitempty"`
ForksCount *int `json:"forks_count,omitempty"`
Archived *bool `json:"archived,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
DefaultBranch *string `json:"default_branch,omitempty"`
MasterBranch *string `json:"master_branch,omitempty"`
Organization *string `json:"organization,omitempty"`
URL *string `json:"url,omitempty"`
ArchiveURL *string `json:"archive_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
StatusesURL *string `json:"statuses_url,omitempty"`
GitURL *string `json:"git_url,omitempty"`
SSHURL *string `json:"ssh_url,omitempty"`
CloneURL *string `json:"clone_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"`
Topics []string `json:"topics,omitempty"`
CustomProperties map[string]any `json:"custom_properties,omitempty"`
}

// PushEventRepoOwner is a basic representation of user/org in a PushEvent payload.
Expand Down
14 changes: 7 additions & 7 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5644,7 +5644,7 @@ func TestDeploymentEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &DeploymentEvent{}, "{}")

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"

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

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"

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

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"

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

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"
hookConfig := new(HookConfig)

Expand Down Expand Up @@ -8773,7 +8773,7 @@ func TestRepositoryDispatchEvent_Marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &RepositoryDispatchEvent{}, "{}")

l := make(map[string]interface{})
l := make(map[string]any)
l["key"] = "value"

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

i := make(map[string]interface{})
i := make(map[string]any)
i["key"] = "value"

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

v := make(map[string]interface{})
v := make(map[string]any)
v["a"] = "b"
hookConfig := &HookConfig{
ContentType: Ptr("json"),
Expand Down
2 changes: 1 addition & 1 deletion github/gen-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
}
)

func logf(fmt string, args ...interface{}) {
func logf(fmt string, args ...any) {
if *verbose {
log.Printf(fmt, args...)
}
Expand Down
6 changes: 5 additions & 1 deletion github/gen-stringify-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var (
return `[""]`
case "[]Scope{ScopeNone}":
return `["(no scope)"]`
case "[]any{nil}":
return "[<nil>]"
}
log.Fatalf("Unhandled zero value: %q", v)
return ""
Expand Down Expand Up @@ -311,6 +313,8 @@ func (t *templateData) addIdentSlice(x *ast.Ident, receiverType, fieldName strin
zeroValue = "[]bool{false}"
case "Scope":
zeroValue = "[]Scope{ScopeNone}"
case "any":
zeroValue = "[]any{nil}"
// case "Timestamp":
// zeroValue = "&Timestamp{}"
default:
Expand Down Expand Up @@ -377,7 +381,7 @@ func newStructField(receiverType, fieldName, fieldType, zeroValue string, namedS
}
}

func logf(fmt string, args ...interface{}) {
func logf(fmt string, args ...any) {
if *verbose {
log.Printf(fmt, args...)
}
Expand Down
6 changes: 3 additions & 3 deletions github/git_trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (s *GitService) GetTree(ctx context.Context, owner string, repo string, sha

// createTree represents the body of a CreateTree request.
type createTree struct {
BaseTree string `json:"base_tree,omitempty"`
Entries []interface{} `json:"tree"`
BaseTree string `json:"base_tree,omitempty"`
Entries []any `json:"tree"`
}

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

newEntries := make([]interface{}, 0, len(entries))
newEntries := make([]any, 0, len(entries))
for _, entry := range entries {
if entry.Content == nil && entry.SHA == nil {
newEntries = append(newEntries, treeEntryWithFileDelete{
Expand Down
2 changes: 1 addition & 1 deletion github/git_trees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func TestCreateTree_Marshal(t *testing.T) {

u := &createTree{
BaseTree: "bt",
Entries: []interface{}{"e"},
Entries: []any{"e"},
}

want := `{
Expand Down
Loading
Loading