Skip to content

🌱 Enable lint check empty-block and fix issues #4459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ linters-settings:
- name: indent-error-flow
- name: errorf
- name: empty-block
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
Expand Down Expand Up @@ -85,3 +84,4 @@ linters:
- unconvert
- unparam
- unused

6 changes: 2 additions & 4 deletions pkg/cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,13 @@ var _ = Describe("Discover external plugins", func() {

It("should return error when home directory is set to empty", func() {
_, ok := os.LookupEnv("XDG_CONFIG_HOME")
if !ok {
} else {
if ok {
err = os.Setenv("XDG_CONFIG_HOME", "")
Expect(err).ToNot(HaveOccurred())
}

_, ok = os.LookupEnv("HOME")
if !ok {
} else {
if ok {
err = os.Setenv("HOME", "")
Expect(err).ToNot(HaveOccurred())
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/store/yaml/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func (s yamlStore) SaveTo(path string) error {

// If it is a new configuration, the path should not exist yet
if s.mustNotExist {
// Lets check that the file doesn't exist
// Check that the file doesn't exist
_, err := s.fs.Stat(path)
if os.IsNotExist(err) {
// This is exactly what we want
} else if err == nil || os.IsExist(err) {
if err == nil || os.IsExist(err) {
// File already exists
return store.SaveError{Err: fmt.Errorf("configuration already exists in %q", path)}
} else {
} else if !os.IsNotExist(err) {
// Error occurred while checking file existence
return store.SaveError{Err: fmt.Errorf("unable to check for file prior existence: %w", err)}
}
}
Expand Down
45 changes: 22 additions & 23 deletions pkg/plugins/golang/deploy-image/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,29 +192,28 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
// Track the resources following a declarative approach
cfg := PluginConfig{}
if err := p.config.DecodePluginConfig(pluginKey, &cfg); errors.As(err, &config.UnsupportedFieldError{}) {
// Config doesn't support per-plugin configuration, so we can't track them
} else {
// Fail unless they key wasn't found, which just means it is the first resource tracked
if err != nil && !errors.As(err, &config.PluginKeyNotFoundError{}) {
return err
}
configDataOptions := options{
Image: p.image,
ContainerCommand: p.imageContainerCommand,
ContainerPort: p.imageContainerPort,
RunAsUser: p.runAsUser,
}
cfg.Resources = append(cfg.Resources, ResourceData{
Group: p.resource.GVK.Group,
Domain: p.resource.GVK.Domain,
Version: p.resource.GVK.Version,
Kind: p.resource.GVK.Kind,
Options: configDataOptions,
},
)
if err := p.config.EncodePluginConfig(pluginKey, cfg); err != nil {
return err
}
// Skip tracking as the config doesn't support per-plugin configuration
return nil
} else if err != nil && !errors.As(err, &config.PluginKeyNotFoundError{}) {
// Fail unless the key wasn't found, which just means it is the first resource tracked
return err
}

configDataOptions := options{
Image: p.image,
ContainerCommand: p.imageContainerCommand,
ContainerPort: p.imageContainerPort,
RunAsUser: p.runAsUser,
}
cfg.Resources = append(cfg.Resources, ResourceData{
Group: p.resource.GVK.Group,
Domain: p.resource.GVK.Domain,
Version: p.resource.GVK.Version,
Kind: p.resource.GVK.Kind,
Options: configDataOptions,
})
if err := p.config.EncodePluginConfig(pluginKey, cfg); err != nil {
return err
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ type Boilerplate struct {

// Validate implements file.RequiresValidation
func (f Boilerplate) Validate() error {
if f.License == "" {
// A default license will be set later
} else if _, found := knownLicenses[f.License]; found {
// One of the know licenses
} else if _, found := f.Licenses[f.License]; found {
// A map containing the requested license was also provided
} else {
return fmt.Errorf("unknown specified license %s", f.License)
if f.License != "" {
if _, found := knownLicenses[f.License]; !found {
if _, found := f.Licenses[f.License]; !found {
return fmt.Errorf("unknown specified license %s", f.License)
}
}
}

return nil
}

Expand Down
Loading