Skip to content

Commit 1d12979

Browse files
🌱 Enable lint check empty-block and fix issues (#4459)
enable lint check empty-block and fix issues
1 parent 06b67eb commit 1d12979

File tree

5 files changed

+36
-42
lines changed

5 files changed

+36
-42
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ linters-settings:
4949
- name: indent-error-flow
5050
- name: errorf
5151
- name: empty-block
52-
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
5352
- name: superfluous-else
5453
- name: unused-parameter
5554
- name: unreachable-code
@@ -85,3 +84,4 @@ linters:
8584
- unconvert
8685
- unparam
8786
- unused
87+

pkg/cli/options_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,13 @@ var _ = Describe("Discover external plugins", func() {
432432

433433
It("should return error when home directory is set to empty", func() {
434434
_, ok := os.LookupEnv("XDG_CONFIG_HOME")
435-
if !ok {
436-
} else {
435+
if ok {
437436
err = os.Setenv("XDG_CONFIG_HOME", "")
438437
Expect(err).ToNot(HaveOccurred())
439438
}
440439

441440
_, ok = os.LookupEnv("HOME")
442-
if !ok {
443-
} else {
441+
if ok {
444442
err = os.Setenv("HOME", "")
445443
Expect(err).ToNot(HaveOccurred())
446444
}

pkg/config/store/yaml/store.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ func (s yamlStore) SaveTo(path string) error {
123123

124124
// If it is a new configuration, the path should not exist yet
125125
if s.mustNotExist {
126-
// Lets check that the file doesn't exist
126+
// Check that the file doesn't exist
127127
_, err := s.fs.Stat(path)
128-
if os.IsNotExist(err) {
129-
// This is exactly what we want
130-
} else if err == nil || os.IsExist(err) {
128+
if err == nil || os.IsExist(err) {
129+
// File already exists
131130
return store.SaveError{Err: fmt.Errorf("configuration already exists in %q", path)}
132-
} else {
131+
} else if !os.IsNotExist(err) {
132+
// Error occurred while checking file existence
133133
return store.SaveError{Err: fmt.Errorf("unable to check for file prior existence: %w", err)}
134134
}
135135
}

pkg/plugins/golang/deploy-image/v1alpha1/api.go

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,28 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
192192
// Track the resources following a declarative approach
193193
cfg := PluginConfig{}
194194
if err := p.config.DecodePluginConfig(pluginKey, &cfg); errors.As(err, &config.UnsupportedFieldError{}) {
195-
// Config doesn't support per-plugin configuration, so we can't track them
196-
} else {
197-
// Fail unless they key wasn't found, which just means it is the first resource tracked
198-
if err != nil && !errors.As(err, &config.PluginKeyNotFoundError{}) {
199-
return err
200-
}
201-
configDataOptions := options{
202-
Image: p.image,
203-
ContainerCommand: p.imageContainerCommand,
204-
ContainerPort: p.imageContainerPort,
205-
RunAsUser: p.runAsUser,
206-
}
207-
cfg.Resources = append(cfg.Resources, ResourceData{
208-
Group: p.resource.GVK.Group,
209-
Domain: p.resource.GVK.Domain,
210-
Version: p.resource.GVK.Version,
211-
Kind: p.resource.GVK.Kind,
212-
Options: configDataOptions,
213-
},
214-
)
215-
if err := p.config.EncodePluginConfig(pluginKey, cfg); err != nil {
216-
return err
217-
}
195+
// Skip tracking as the config doesn't support per-plugin configuration
196+
return nil
197+
} else if err != nil && !errors.As(err, &config.PluginKeyNotFoundError{}) {
198+
// Fail unless the key wasn't found, which just means it is the first resource tracked
199+
return err
200+
}
201+
202+
configDataOptions := options{
203+
Image: p.image,
204+
ContainerCommand: p.imageContainerCommand,
205+
ContainerPort: p.imageContainerPort,
206+
RunAsUser: p.runAsUser,
207+
}
208+
cfg.Resources = append(cfg.Resources, ResourceData{
209+
Group: p.resource.GVK.Group,
210+
Domain: p.resource.GVK.Domain,
211+
Version: p.resource.GVK.Version,
212+
Kind: p.resource.GVK.Kind,
213+
Options: configDataOptions,
214+
})
215+
if err := p.config.EncodePluginConfig(pluginKey, cfg); err != nil {
216+
return err
218217
}
219218

220219
return nil

pkg/plugins/golang/v4/scaffolds/internal/templates/hack/boilerplate.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@ type Boilerplate struct {
4949

5050
// Validate implements file.RequiresValidation
5151
func (f Boilerplate) Validate() error {
52-
if f.License == "" {
53-
// A default license will be set later
54-
} else if _, found := knownLicenses[f.License]; found {
55-
// One of the know licenses
56-
} else if _, found := f.Licenses[f.License]; found {
57-
// A map containing the requested license was also provided
58-
} else {
59-
return fmt.Errorf("unknown specified license %s", f.License)
52+
if f.License != "" {
53+
if _, found := knownLicenses[f.License]; !found {
54+
if _, found := f.Licenses[f.License]; !found {
55+
return fmt.Errorf("unknown specified license %s", f.License)
56+
}
57+
}
6058
}
61-
6259
return nil
6360
}
6461

0 commit comments

Comments
 (0)