From 8b419f624fb489ce736644edfa94c7c97230970a Mon Sep 17 00:00:00 2001 From: Selene Date: Tue, 11 Jul 2023 16:41:18 +0200 Subject: [PATCH] Format go resource (#71370) * Format Go resource * Format tabs * use format library * Undo template change * Apply suggestion --- pkg/codegen/jenny_go_resources.go | 9 ++++++++- pkg/codegen/tmpl/core_resource.tmpl | 1 - pkg/kinds/accesspolicy/accesspolicy_gen.go | 5 ++--- pkg/kinds/dashboard/dashboard_gen.go | 5 ++--- pkg/kinds/folder/folder_gen.go | 5 ++--- pkg/kinds/librarypanel/librarypanel_gen.go | 5 ++--- pkg/kinds/playlist/playlist_gen.go | 5 ++--- pkg/kinds/preferences/preferences_gen.go | 5 ++--- pkg/kinds/publicdashboard/publicdashboard_gen.go | 5 ++--- pkg/kinds/role/role_gen.go | 5 ++--- pkg/kinds/rolebinding/rolebinding_gen.go | 5 ++--- pkg/kinds/team/team_gen.go | 5 ++--- 12 files changed, 28 insertions(+), 32 deletions(-) diff --git a/pkg/codegen/jenny_go_resources.go b/pkg/codegen/jenny_go_resources.go index 5b646f0d594..13216f0d6c2 100644 --- a/pkg/codegen/jenny_go_resources.go +++ b/pkg/codegen/jenny_go_resources.go @@ -3,6 +3,7 @@ package codegen import ( "bytes" "fmt" + "go/format" "strings" "cuelang.org/go/cue" @@ -57,7 +58,13 @@ func (ag *ResourceGoTypesJenny) Generate(kind kindsys.Kind) (*codejen.File, erro if err != nil { return nil, err } - return codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_gen.go", mname, mname), buf.Bytes(), ag), nil + + content, err := format.Source(buf.Bytes()) + if err != nil { + return nil, err + } + + return codejen.NewFile(fmt.Sprintf("pkg/kinds/%s/%s_gen.go", mname, mname), content, ag), nil } type SubresourceGoTypesJenny struct { diff --git a/pkg/codegen/tmpl/core_resource.tmpl b/pkg/codegen/tmpl/core_resource.tmpl index fed3ced9051..01207539348 100644 --- a/pkg/codegen/tmpl/core_resource.tmpl +++ b/pkg/codegen/tmpl/core_resource.tmpl @@ -21,7 +21,6 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of {{ .KindName }}. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { diff --git a/pkg/kinds/accesspolicy/accesspolicy_gen.go b/pkg/kinds/accesspolicy/accesspolicy_gen.go index b7cba028b33..b2833e0fd94 100644 --- a/pkg/kinds/accesspolicy/accesspolicy_gen.go +++ b/pkg/kinds/accesspolicy/accesspolicy_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of AccessPolicy. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/dashboard/dashboard_gen.go b/pkg/kinds/dashboard/dashboard_gen.go index 64955699584..100a4683644 100644 --- a/pkg/kinds/dashboard/dashboard_gen.go +++ b/pkg/kinds/dashboard/dashboard_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Dashboard. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/folder/folder_gen.go b/pkg/kinds/folder/folder_gen.go index 9a34bdae955..c0d9f669d22 100644 --- a/pkg/kinds/folder/folder_gen.go +++ b/pkg/kinds/folder/folder_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Folder. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/librarypanel/librarypanel_gen.go b/pkg/kinds/librarypanel/librarypanel_gen.go index f30dc2d7b7b..92a8bb9c220 100644 --- a/pkg/kinds/librarypanel/librarypanel_gen.go +++ b/pkg/kinds/librarypanel/librarypanel_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of LibraryPanel. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/playlist/playlist_gen.go b/pkg/kinds/playlist/playlist_gen.go index 8bd8b6ac05e..b0ec8a23ca3 100644 --- a/pkg/kinds/playlist/playlist_gen.go +++ b/pkg/kinds/playlist/playlist_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Playlist. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/preferences/preferences_gen.go b/pkg/kinds/preferences/preferences_gen.go index 610d46ea2f7..16606278917 100644 --- a/pkg/kinds/preferences/preferences_gen.go +++ b/pkg/kinds/preferences/preferences_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Preferences. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/publicdashboard/publicdashboard_gen.go b/pkg/kinds/publicdashboard/publicdashboard_gen.go index fdecdb5f974..ab3789a6241 100644 --- a/pkg/kinds/publicdashboard/publicdashboard_gen.go +++ b/pkg/kinds/publicdashboard/publicdashboard_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of PublicDashboard. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/role/role_gen.go b/pkg/kinds/role/role_gen.go index 20d99cabb1c..312653b71cb 100644 --- a/pkg/kinds/role/role_gen.go +++ b/pkg/kinds/role/role_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Role. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/rolebinding/rolebinding_gen.go b/pkg/kinds/rolebinding/rolebinding_gen.go index ae30f61ade3..c0395ed55bc 100644 --- a/pkg/kinds/rolebinding/rolebinding_gen.go +++ b/pkg/kinds/rolebinding/rolebinding_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of RoleBinding. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` } diff --git a/pkg/kinds/team/team_gen.go b/pkg/kinds/team/team_gen.go index 1002362359a..39aec6e3939 100644 --- a/pkg/kinds/team/team_gen.go +++ b/pkg/kinds/team/team_gen.go @@ -30,11 +30,10 @@ func NewK8sResource(name string, s *Spec) K8sResource { } } - // Resource is the wire representation of Team. // It currently will soon be merged into the k8s flavor (TODO be better) type Resource struct { Metadata Metadata `json:"metadata"` - Spec Spec `json:"spec"` - Status Status `json:"status"` + Spec Spec `json:"spec"` + Status Status `json:"status"` }