Skip to content

Commit 22ec856

Browse files
committed
run golangci-lint and make it happy
disabling prealloc linter because its documentation states: > IMPORTANT: we don't recommend using this linter before doing performance profiling. > For most programs usage of prealloc will be a premature optimization. On-behalf-of: @SAP [email protected]
1 parent a20e483 commit 22ec856

25 files changed

+94
-125
lines changed

.golangci.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ linters:
1010
- bidichk
1111
- bodyclose
1212
- containedctx
13+
- copyloopvar
1314
- dupword
1415
- durationcheck
1516
- errcheck
1617
- errchkjson
17-
- exportloopref
1818
- gocritic
1919
- godot
2020
- gofmt
@@ -29,10 +29,17 @@ linters:
2929
- noctx
3030
- nolintlint
3131
- nosprintfhostport
32-
- prealloc
3332
- revive
3433
- staticcheck
3534
- unconvert
3635
- unused
3736
- usestdlibvars
3837
- whitespace
38+
39+
linters-settings:
40+
revive:
41+
rules:
42+
# That is just how the Kubernetes code-generators are written.
43+
# We'd rather stay closer to upstream than fixing this.
44+
- name: unexported-return
45+
disabled: true

cmd/cluster-client-gen/args/gvpackages.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ func NewInputBasePathValue(builder *groupVersionsBuilder, def string) *inputBase
3939
v := &inputBasePathValue{
4040
builder: builder,
4141
}
42-
v.Set(def)
42+
if err := v.Set(def); err != nil {
43+
panic(err)
44+
}
4345
return v
4446
}
4547

cmd/cluster-client-gen/generators/client_generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ NextGroup:
278278
// comment of the form "// +groupName=somegroup" or "// +groupName=somegroup.foo.bar.io", use the
279279
// first field (somegroup) as the name of the group in Go code, e.g. as the func name in a clientset.
280280
//
281-
// If the first field of the groupName is not unique within the clientset, use "// +groupName=unique
281+
// If the first field of the groupName is not unique within the clientset, use "// +groupName=unique".
282282
func applyGroupOverrides(universe types.Universe, args *args.Args) {
283283
// Create a map from "old GV" to "new GV" so we know what changes we need to make.
284284
changes := make(map[clientgentypes.GroupVersion]clientgentypes.GroupVersion)
@@ -415,7 +415,7 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
415415

416416
// If --clientset-only=true, we don't regenerate the individual typed clients.
417417
if args.ClientsetOnly {
418-
return []generator.Target(targetList)
418+
return targetList
419419
}
420420

421421
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}

cmd/cluster-client-gen/generators/fake/fake_client_generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TargetForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clie
8585
})
8686
return generators
8787
},
88-
FilterFunc: func(c *generator.Context, t *types.Type) bool {
88+
FilterFunc: func(_ *generator.Context, t *types.Type) bool {
8989
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
9090
},
9191
}
@@ -102,7 +102,7 @@ func TargetForClientset(args *args.Args, clientsetDir, clientsetPkg string, sing
102102
PkgDocComment: []byte("// This package has the automatically generated fake clientset.\n"),
103103
// GeneratorsFunc returns a list of generators. Each generator generates a
104104
// single file.
105-
GeneratorsFunc: func(c *generator.Context) (generators []generator.Generator) {
105+
GeneratorsFunc: func(_ *generator.Context) (generators []generator.Generator) {
106106
generators = []generator.Generator{
107107
// Always generate a "doc.go" file.
108108
generator.GoGenerator{OutputFilename: "doc.go"},

cmd/cluster-client-gen/generators/fake/generator_fake_for_clientset.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ type genClientset struct {
4646

4747
var _ generator.Generator = &genClientset{}
4848

49-
func (g *genClientset) Namers(c *generator.Context) namer.NameSystems {
49+
func (g *genClientset) Namers(_ *generator.Context) namer.NameSystems {
5050
return namer.NameSystems{
5151
"raw": namer.NewRawNamer(g.fakeClientsetPackage, g.imports),
5252
}
5353
}
5454

5555
// We only want to call GenerateType() once.
56-
func (g *genClientset) Filter(c *generator.Context, t *types.Type) bool {
56+
func (g *genClientset) Filter(_ *generator.Context, _ *types.Type) bool {
5757
ret := !g.clientsetGenerated
5858
g.clientsetGenerated = true
5959
return ret
6060
}
6161

62-
func (g *genClientset) Imports(c *generator.Context) (imports []string) {
62+
func (g *genClientset) Imports(_ *generator.Context) (imports []string) {
6363
imports = append(imports, g.imports.ImportLines()...)
6464
for _, group := range g.groups {
6565
for _, version := range group.Versions {
@@ -93,7 +93,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
9393
return
9494
}
9595

96-
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
96+
func (g *genClientset) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error {
9797
generateApply := len(g.applyConfigurationPackage) > 0
9898

9999
// TODO: We actually don't need any type information to generate the clientset,

cmd/cluster-client-gen/generators/fake/generator_fake_for_group.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ type genFakeForGroup struct {
4848
var _ generator.Generator = &genFakeForGroup{}
4949

5050
// We only want to call GenerateType() once per group.
51-
func (g *genFakeForGroup) Filter(c *generator.Context, t *types.Type) bool {
51+
func (g *genFakeForGroup) Filter(_ *generator.Context, _ *types.Type) bool {
5252
if !g.called {
5353
g.called = true
5454
return true
5555
}
5656
return false
5757
}
5858

59-
func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
59+
func (g *genFakeForGroup) Namers(_ *generator.Context) namer.NameSystems {
6060
return namer.NameSystems{
6161
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
6262
}
@@ -69,7 +69,7 @@ func groupVersionFromPackage(pkg string) string {
6969
return strings.ToLower(group + version)
7070
}
7171

72-
func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
72+
func (g *genFakeForGroup) Imports(_ *generator.Context) (imports []string) {
7373
imports = g.imports.ImportLines()
7474
if len(g.types) != 0 {
7575
imports = append(imports,
@@ -81,7 +81,7 @@ func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
8181
return imports
8282
}
8383

84-
func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
84+
func (g *genFakeForGroup) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error {
8585
sw := generator.NewSnippetWriter(w, c, "$", "$")
8686
gv := groupVersionFromPackage(g.realClientPackage)
8787

cmd/cluster-client-gen/generators/fake/generator_fake_for_type.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ var _ generator.Generator = &genFakeForType{}
5252
var titler = cases.Title(language.Und)
5353

5454
// Filter ignores all but one type because we're making a single file per type.
55-
func (g *genFakeForType) Filter(c *generator.Context, t *types.Type) bool { return t == g.typeToMatch }
55+
func (g *genFakeForType) Filter(_ *generator.Context, t *types.Type) bool {
56+
return t == g.typeToMatch
57+
}
5658

57-
func (g *genFakeForType) Namers(c *generator.Context) namer.NameSystems {
59+
func (g *genFakeForType) Namers(_ *generator.Context) namer.NameSystems {
5860
return namer.NameSystems{
5961
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
6062
}
6163
}
6264

63-
func (g *genFakeForType) Imports(c *generator.Context) (imports []string) {
65+
func (g *genFakeForType) Imports(_ *generator.Context) (imports []string) {
6466
gvAlias := util.GroupVersionAliasFromPackage(g.realClientPackage)
6567

6668
imports = append(imports, g.imports.ImportLines()...)
@@ -297,7 +299,7 @@ func adjustTemplate(name, verbType, template string) string {
297299
return strings.ReplaceAll(template, " "+titler.String(verbType), " "+name)
298300
}
299301

300-
// struct and constructor variants
302+
// struct and constructor variants.
301303
const (
302304
// The following values are bits in a bitmask.
303305
// The values which can be set indicate list support and apply support;
@@ -317,7 +319,7 @@ const (
317319
// * withList, withApply: index 3.
318320
// Go enforces index unicity in these kinds of declarations.
319321

320-
// cluster struct declarations
322+
// cluster struct declarations.
321323
var listableClusterClientType = `
322324
// $.type|private$ClusterClient implements $.type|singularKind$ClusterInterface
323325
type $.type|private$ClusterClient struct {
@@ -334,7 +336,7 @@ type $.type|private$ClusterClient struct {
334336
}
335337
`
336338

337-
// Constructors for the cluster struct, in all variants
339+
// Constructors for the cluster struct, in all variants.
338340
var newListableClusterClient = `
339341
func newFake$.type|public$ClusterClient(fake *$.GroupGoName$$.Version$ClusterClient) typedkcp$.groupVersion$.$.type|singularKind$ClusterInterface {
340342
return &$.type|private$ClusterClient{
@@ -388,7 +390,7 @@ func (n *$.type|private$Namespacer) Namespace(namespace string) typed$.groupVers
388390
}
389391
`
390392

391-
// scoped struct declarations
393+
// scoped struct declarations.
392394
var clientStructType = []string{
393395
noList | noApply: `
394396
// $.type|private$ScopedClient implements $.type|public$Interface
@@ -424,7 +426,7 @@ var clientStructType = []string{
424426
`,
425427
}
426428

427-
// Constructors for the scoped struct, in all variants
429+
// Constructors for the scoped struct, in all variants.
428430
var newClientStruct = []string{
429431
noList | noApply: `
430432
func newFake$.type|public$Client(fake *kcptesting.Fake$if .namespaced$, namespace string$end$, clusterPath logicalcluster.Path) typed$.groupVersion$.$.type|singularKind$Interface {

cmd/cluster-client-gen/generators/generator_for_clientset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ type genClientset struct {
4343

4444
var _ generator.Generator = &genClientset{}
4545

46-
func (g *genClientset) Namers(c *generator.Context) namer.NameSystems {
46+
func (g *genClientset) Namers(_ *generator.Context) namer.NameSystems {
4747
return namer.NameSystems{
4848
"raw": namer.NewRawNamer(g.clientsetPackage, g.imports),
4949
}
5050
}
5151

5252
// We only want to call GenerateType() once.
53-
func (g *genClientset) Filter(c *generator.Context, t *types.Type) bool {
53+
func (g *genClientset) Filter(_ *generator.Context, _ *types.Type) bool {
5454
ret := !g.clientsetGenerated
5555
g.clientsetGenerated = true
5656
return ret
@@ -72,7 +72,7 @@ func (g *genClientset) Imports(c *generator.Context) (imports []string) {
7272
return
7373
}
7474

75-
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
75+
func (g *genClientset) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error {
7676
// TODO: We actually don't need any type information to generate the clientset,
7777
// perhaps we can adapt the go2ild framework to this kind of usage.
7878
sw := generator.NewSnippetWriter(w, c, "$", "$")

cmd/cluster-client-gen/generators/generator_for_expansion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ type genExpansion struct {
3636
}
3737

3838
// We only want to call GenerateType() once per group.
39-
func (g *genExpansion) Filter(c *generator.Context, t *types.Type) bool {
39+
func (g *genExpansion) Filter(_ *generator.Context, t *types.Type) bool {
4040
return len(g.types) == 0 || t == g.types[0]
4141
}
4242

43-
func (g *genExpansion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
43+
func (g *genExpansion) GenerateType(c *generator.Context, _ *types.Type, w io.Writer) error {
4444
sw := generator.NewSnippetWriter(w, c, "$", "$")
4545
for _, t := range g.types {
4646
if _, err := os.Stat(filepath.Join(g.groupPackagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {

cmd/cluster-client-gen/generators/generator_for_group.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package generators
2020
import (
2121
"io"
2222
"path"
23-
"strings"
2423

2524
"k8s.io/gengo/v2"
2625
"k8s.io/gengo/v2/generator"
@@ -49,28 +48,21 @@ type genGroup struct {
4948
var _ generator.Generator = &genGroup{}
5049

5150
// We only want to call GenerateType() once per group.
52-
func (g *genGroup) Filter(c *generator.Context, t *types.Type) bool {
51+
func (g *genGroup) Filter(_ *generator.Context, _ *types.Type) bool {
5352
if !g.called {
5453
g.called = true
5554
return true
5655
}
5756
return false
5857
}
5958

60-
func (g *genGroup) Namers(c *generator.Context) namer.NameSystems {
59+
func (g *genGroup) Namers(_ *generator.Context) namer.NameSystems {
6160
return namer.NameSystems{
6261
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
6362
}
6463
}
6564

66-
func groupVersionFromPackage(pkg string) string {
67-
version := path.Base(pkg)
68-
group := path.Base(path.Dir(pkg))
69-
70-
return strings.ToLower(group + version)
71-
}
72-
73-
func (g *genGroup) Imports(c *generator.Context) (imports []string) {
65+
func (g *genGroup) Imports(_ *generator.Context) (imports []string) {
7466
imports = append(imports, g.imports.ImportLines()...)
7567
imports = append(imports,
7668
"github.com/kcp-dev/logicalcluster/v3",

0 commit comments

Comments
 (0)