Skip to content

Commit ebb8fd2

Browse files
authored
🌱 (chore): simplify variable declarations by removing unnecessary var blocks (#4667)
chore: simplify variable declarations by removing unnecessary var blocks Converted single-variable `var (...)` blocks to direct `var` declarations in various packages such as `golang/options.go`, `cli/root.go`, `config/registry.go`, and test files. This makes the code more concise and aligns with idiomatic Go style.
1 parent 4f844d0 commit ebb8fd2

File tree

6 files changed

+30
-42
lines changed

6 files changed

+30
-42
lines changed

‎pkg/cli/root.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const (
2929
projectVersionsHeader = "Supported project versions"
3030
)
3131

32-
var (
33-
supportedPlatforms = []string{"darwin", "linux"}
34-
)
32+
var supportedPlatforms = []string{"darwin", "linux"}
3533

3634
func (c CLI) newRootCmd() *cobra.Command {
3735
cmd := &cobra.Command{

‎pkg/config/registry.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ limitations under the License.
1616

1717
package config
1818

19-
var (
20-
registry = make(map[Version]func() Config)
21-
)
19+
var registry = make(map[Version]func() Config)
2220

2321
// Register allows implementations of Config to register themselves so that they can be created with New
2422
func Register(version Version, constructor func() Config) {

‎pkg/plugins/golang/go_version.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ const (
2828
goVerPattern = `^go(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(?:\.(?P<patch>[0-9]+)|(?P<pre>(?:alpha|beta|rc)[0-9]+))?$`
2929
)
3030

31-
var (
32-
goVerRegexp = regexp.MustCompile(goVerPattern)
33-
)
31+
var goVerRegexp = regexp.MustCompile(goVerPattern)
3432

3533
// GoVersion describes a Go version.
3634
type GoVersion struct {

‎pkg/plugins/golang/options.go

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,31 @@ import (
2323
"sigs.k8s.io/kubebuilder/v4/pkg/model/resource"
2424
)
2525

26-
var (
27-
coreGroups = map[string]string{
28-
"admission": "k8s.io",
29-
"admissionregistration": "k8s.io",
30-
"apps": "",
31-
"auditregistration": "k8s.io",
32-
"apiextensions": "k8s.io",
33-
"authentication": "k8s.io",
34-
"authorization": "k8s.io",
35-
"autoscaling": "",
36-
"batch": "",
37-
"certificates": "k8s.io",
38-
"coordination": "k8s.io",
39-
"core": "",
40-
"events": "k8s.io",
41-
"extensions": "",
42-
"imagepolicy": "k8s.io",
43-
"networking": "k8s.io",
44-
"node": "k8s.io",
45-
"metrics": "k8s.io",
46-
"policy": "",
47-
"rbac.authorization": "k8s.io",
48-
"scheduling": "k8s.io",
49-
"setting": "k8s.io",
50-
"storage": "k8s.io",
51-
}
52-
)
26+
var coreGroups = map[string]string{
27+
"admission": "k8s.io",
28+
"admissionregistration": "k8s.io",
29+
"apps": "",
30+
"auditregistration": "k8s.io",
31+
"apiextensions": "k8s.io",
32+
"authentication": "k8s.io",
33+
"authorization": "k8s.io",
34+
"autoscaling": "",
35+
"batch": "",
36+
"certificates": "k8s.io",
37+
"coordination": "k8s.io",
38+
"core": "",
39+
"events": "k8s.io",
40+
"extensions": "",
41+
"imagepolicy": "k8s.io",
42+
"networking": "k8s.io",
43+
"node": "k8s.io",
44+
"metrics": "k8s.io",
45+
"policy": "",
46+
"rbac.authorization": "k8s.io",
47+
"scheduling": "k8s.io",
48+
"setting": "k8s.io",
49+
"storage": "k8s.io",
50+
}
5351

5452
// Options contains the information required to build a new resource.Resource.
5553
type Options struct {

‎pkg/plugins/optional/grafana/v1alpha/plugin.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ type Plugin struct {
3838
editSubcommand
3939
}
4040

41-
var (
42-
_ plugin.Init = Plugin{}
43-
)
41+
var _ plugin.Init = Plugin{}
4442

4543
// Name returns the name of the plugin
4644
func (Plugin) Name() string { return pluginName }

‎test/e2e/grafana/generate_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import (
3030

3131
var _ = Describe("kubebuilder", func() {
3232
Context("plugin grafana/v1-alpha", func() {
33-
var (
34-
kbc *utils.TestContext
35-
)
33+
var kbc *utils.TestContext
3634

3735
BeforeEach(func() {
3836
var err error

0 commit comments

Comments
 (0)