Skip to content

Commit

Permalink
Address issues raised by linter (comment/error format and pre-allocat…
Browse files Browse the repository at this point in the history
…ion)

Signed-off-by: Marvin Beckers <[email protected]>
  • Loading branch information
embik committed Jan 25, 2024
1 parent aede36a commit e7233a1
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions examples/pkg/apis/example/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (

const GroupName = "example.dev"

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/example/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"acme.corp/pkg/apis/example"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/example/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"acme.corp/pkg/apis/example"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1alpha1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/example/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"acme.corp/pkg/apis/example"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1beta1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/example/v2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"acme.corp/pkg/apis/example"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v2"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/example3/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
example "acme.corp/pkg/apis/example3"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/existinginterfaces/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
"acme.corp/pkg/apis/existinginterfaces"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: existinginterfaces.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
6 changes: 3 additions & 3 deletions examples/pkg/apis/secondexample/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import (
example "acme.corp/pkg/apis/secondexample"
)

// SchemeGroupVersion is group version used to register these objects
// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
// Kind takes an unqualified kind and returns back a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Expand Down
24 changes: 12 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ var (
// them names for use on the command line.
// Each output rule turns into two command line options:
// - output:<generator>:<form> (per-generator output)
// - output:<form> (default output)
// - output:<form> (default output).
allOutputRules = map[string]genall.OutputRule{
"dir": genall.OutputToDirectory(""),
"none": genall.OutputToNothing,
"stdout": genall.OutputToStdout,
"artifacts": genall.OutputArtifacts{},
}

// optionsRegistry contains all the marker definitions used to process command line options
// optionsRegistry contains all the marker definitions used to process command line options.
optionsRegistry = &markers.Registry{}
)

func init() {
for genName, gen := range allGenerators {
// make the generator options marker itself
// make the generator options marker itself.
defn := markers.Must(markers.MakeDefinition(genName, markers.DescribesPackage, gen))
if err := optionsRegistry.Register(defn); err != nil {
panic(err)
Expand All @@ -80,7 +80,7 @@ func init() {
}
}

// make per-generation output rule markers
// make per-generation output rule markers.
for ruleName, rule := range allOutputRules {
ruleMarker := markers.Must(markers.MakeDefinition(fmt.Sprintf("output:%s:%s", genName, ruleName), markers.DescribesPackage, rule))
if err := optionsRegistry.Register(ruleMarker); err != nil {
Expand All @@ -94,7 +94,7 @@ func init() {
}
}

// make "default output" output rule markers
// make "default output" output rule markers.
for ruleName, rule := range allOutputRules {
ruleMarker := markers.Must(markers.MakeDefinition("output:"+ruleName, markers.DescribesPackage, rule))
if err := optionsRegistry.Register(ruleMarker); err != nil {
Expand All @@ -107,7 +107,7 @@ func init() {
}
}

// add in the common options markers
// add in the common options markers.
if err := genall.RegisterOptionsMarkers(optionsRegistry); err != nil {
panic(err)
}
Expand Down Expand Up @@ -143,23 +143,23 @@ func main() {
code-generator lister -ww
`,
RunE: func(c *cobra.Command, rawOpts []string) error {
// print version if asked for it
// print version if asked for it.
if showVersion {
version.Print()
return nil
}

// print the help if we asked for it (since we've got a different help flag :-/), then bail
// print the help if we asked for it (since we've got a different help flag :-/), then bail.
if helpLevel > 0 {
return c.Usage()
}

// print the marker docs if we asked for them, then bail
// print the marker docs if we asked for them, then bail.
if whichLevel > 0 {
return printMarkerDocs(c, rawOpts, whichLevel)
}

// otherwise, set up the runtime for actually running the generators
// otherwise, set up the runtime for actually running the generators.
rt, err := genall.FromOptions(optionsRegistry, rawOpts)
if err != nil {
return err
Expand All @@ -174,7 +174,7 @@ func main() {
}
return nil
},
SilenceUsage: true, // silence the usage, then print it out ourselves if it wasn't suppressed
SilenceUsage: true, // silence the usage, then print it out ourselves if it wasn't suppressed.
}
cmd.Flags().CountVarP(&whichLevel, "which-markers", "w", "print out all markers available with the requested generators\n(up to -www for the most detailed output, or -wwww for json output)")
cmd.Flags().CountVarP(&helpLevel, "detailed-help", "h", "print out more detailed help\n(up to -hhh for the most detailed output, or -hhhh for json output)")
Expand All @@ -194,7 +194,7 @@ func main() {

if err := cmd.Execute(); err != nil {
if _, noUsage := err.(noUsageError); !noUsage {
// print the usage unless we suppressed it
// print the usage unless we suppressed it.
if err := cmd.Usage(); err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/spf13/pflag"
)

// Flags - Options accepted by generator
// Flags are options accepted by the generator.
type Flags struct {
// OutputDir is where the generated code is to be written to.
OutputDir string
Expand Down Expand Up @@ -65,15 +65,15 @@ func (f *Flags) AddTo(flagset *pflag.FlagSet) {
// https://github.com/kcp-dev/code-generator/issues/4
func ValidateFlags(f Flags) error {
if f.InputDir == "" {
return errors.New("input path to API definition is required.")
return errors.New("input path to API definition is required")
}

if f.ClientsetAPIPath == "" {
return errors.New("specifying client API path is required currently.")
return errors.New("specifying client API path is required currently")
}

if len(f.GroupVersions) == 0 {
return errors.New("list of group versions for which the clients are to be generated is required.")
return errors.New("list of group versions for which the clients are to be generated is required")
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/flag/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
. "github.com/onsi/gomega"
)

// TODO: Rewrite into generic Go Testing format
// TODO: Rewrite into generic Go Testing format.
func TestMetadata(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Test flags suite")
Expand All @@ -47,19 +47,19 @@ var _ = Describe("Test flag inputs", func() {
It("verify input path error", func() {
f.InputDir = ""
err := ValidateFlags(f)
Expect(err.Error()).To(ContainSubstring("input path to API definition is required."))
Expect(err.Error()).To(ContainSubstring("input path to API definition is required"))
})

It("verify clientsetAPI path", func() {
f.ClientsetAPIPath = ""
err := ValidateFlags(f)
Expect(err.Error()).To(ContainSubstring("specifying client API path is required currently."))
Expect(err.Error()).To(ContainSubstring("specifying client API path is required currently"))
})

It("verify group version list", func() {
f.GroupVersions = []string{}
err := ValidateFlags(f)
Expect(err.Error()).To(ContainSubstring("list of group versions for which the clients are to be generated is required."))
Expect(err.Error()).To(ContainSubstring("list of group versions for which the clients are to be generated is required"))
})

})
2 changes: 1 addition & 1 deletion pkg/generators/informergen/informergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {

logger := klog.Background()

var onlyGroups []parser.Group
onlyGroups := make([]parser.Group, 0, len(groupVersionKinds))
for group := range groupVersionKinds {
onlyGroups = append(onlyGroups, group)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/markers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func IsNamespaced(info *markers.TypeInfo) bool {
return !IsClusterScoped(info)
}

// SupportedVerbs determines which verbs the type supports
// SupportedVerbs determines which verbs the type supports.
func SupportedVerbs(info *markers.TypeInfo) (sets.Set[string], error) {
if info.Markers.Get(NoVerbsMarker.Name) != nil {
return sets.New[string](), nil
Expand Down Expand Up @@ -146,7 +146,7 @@ func ClientExtensions(info *markers.TypeInfo) []Extension {
if !ok || values == nil {
return nil
}
var extensions []Extension
extensions := make([]Extension, 0, len(values))
for _, item := range values {
extension, ok := item.(extension)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func LowerFirst(s string) string {
return strings.ToLower(string(s[0])) + s[1:]
}

// UpperFirst sets the first alphabet to upperCase/
// UpperFirst sets the first alphabet to upperCase.
func UpperFirst(s string) string {
return strings.ToUpper(string(s[0])) + s[1:]
}
Expand Down

0 comments on commit e7233a1

Please sign in to comment.