From e85a04e3d3b04163b7ddc2b10cc6a36f2cad3528 Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Wed, 27 Nov 2024 11:21:29 +0200 Subject: [PATCH] fix: Lint problems reported by new tools Signed-off-by: Cezar Craciunoiu --- internal/cli/kraft/cloud/volume/import/cpio.go | 2 +- internal/cli/kraft/compose/create/create.go | 2 +- internal/yamlmerger/yamlmerger.go | 2 +- libmocktainer/container_linux.go | 14 ++++++-------- machine/qemu/v1alpha1.go | 2 +- tools/gendocs/main.go | 8 ++------ unikraft/app/application.go | 6 +++--- unikraft/core/core.go | 2 +- unikraft/lib/library.go | 2 +- unikraft/template/template.go | 2 +- 10 files changed, 18 insertions(+), 24 deletions(-) diff --git a/internal/cli/kraft/cloud/volume/import/cpio.go b/internal/cli/kraft/cloud/volume/import/cpio.go index fdc49ab67..9234a8761 100644 --- a/internal/cli/kraft/cloud/volume/import/cpio.go +++ b/internal/cli/kraft/cloud/volume/import/cpio.go @@ -131,7 +131,7 @@ func (r *okResponse) parse(resp []byte) error { } func (r *okResponse) waitForOK(conn *tls.Conn, errorMsg string) ([]byte, error) { - retErr := fmt.Errorf(errorMsg) + retErr := fmt.Errorf("%s", errorMsg) for { // A message can have at max: // status - 4 bytes diff --git a/internal/cli/kraft/compose/create/create.go b/internal/cli/kraft/compose/create/create.go index 9ca20bd85..65a3b7e61 100644 --- a/internal/cli/kraft/compose/create/create.go +++ b/internal/cli/kraft/compose/create/create.go @@ -166,7 +166,7 @@ func (opts *CreateOptions) Run(ctx context.Context, args []string) error { if network.External { continue } - if network.Ipam.Config == nil || len(network.Ipam.Config) == 0 { + if len(network.Ipam.Config) == 0 { emptyNetworks = append(emptyNetworks, name) } else { subnetNetworks = append(subnetNetworks, name) diff --git a/internal/yamlmerger/yamlmerger.go b/internal/yamlmerger/yamlmerger.go index 90fca5b9f..b580b8120 100644 --- a/internal/yamlmerger/yamlmerger.go +++ b/internal/yamlmerger/yamlmerger.go @@ -43,7 +43,7 @@ func RecursiveMerge(from, into *yaml.Node) error { if nodesEqual(from.Content[i], into.Content[j]) { found = true if err := RecursiveMerge(from.Content[i+1], into.Content[j+1]); err != nil { - return fmt.Errorf("at key " + from.Content[i].Value + ": " + err.Error()) + return fmt.Errorf("at key %s: %s", from.Content[i].Value, err.Error()) } break } diff --git a/libmocktainer/container_linux.go b/libmocktainer/container_linux.go index 6a1042f73..ca9bfb4b2 100644 --- a/libmocktainer/container_linux.go +++ b/libmocktainer/container_linux.go @@ -75,7 +75,7 @@ func (c *Container) Status() (Status, error) { func (c *Container) State() (*State, error) { c.m.Lock() defer c.m.Unlock() - return c.currentState() + return c.currentState(), nil } // Start starts a process inside the container. Returns error if process fails @@ -394,11 +394,9 @@ func (c *Container) updateState(process parentProcess) (*State, error) { if process != nil { c.initProcess = process } - state, err := c.currentState() - if err != nil { - return nil, err - } - err = c.saveState(state) + state := c.currentState() + + err := c.saveState(state) if err != nil { return nil, err } @@ -473,7 +471,7 @@ func (c *Container) runType() Status { return Running } -func (c *Container) currentState() (*State, error) { +func (c *Container) currentState() *State { var ( startTime uint64 pid = -1 @@ -507,7 +505,7 @@ func (c *Container) currentState() (*State, error) { } } } - return state, nil + return state } func (c *Container) currentOCIState() (*specs.State, error) { diff --git a/machine/qemu/v1alpha1.go b/machine/qemu/v1alpha1.go index 79ec47906..18edebb76 100644 --- a/machine/qemu/v1alpha1.go +++ b/machine/qemu/v1alpha1.go @@ -517,7 +517,7 @@ func (service *machineV1alpha1Service) Create(ctx context.Context, machine *mach // Propagate the contents of the QEMU log file as an error if errLog, err2 := os.ReadFile(qemuLogFile); err2 == nil { - err = errors.Join(fmt.Errorf(strings.TrimSpace(string(errLog))), err) + err = errors.Join(fmt.Errorf("%s", strings.TrimSpace(string(errLog))), err) } return machine, fmt.Errorf("could not start and wait for QEMU process: %v", err) diff --git a/tools/gendocs/main.go b/tools/gendocs/main.go index 5c780ad14..559bc5492 100644 --- a/tools/gendocs/main.go +++ b/tools/gendocs/main.go @@ -79,9 +79,7 @@ func generateMarkdown(cmd *cobra.Command, dir string) error { buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.Example)) } - if err := printOptions(buf, cmd); err != nil { - return err - } + printOptions(buf, cmd) if hasSeeAlso(cmd) { buf.WriteString("## See Also\n\n") @@ -141,7 +139,7 @@ func generateMarkdown(cmd *cobra.Command, dir string) error { return err } -func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error { +func printOptions(buf *bytes.Buffer, cmd *cobra.Command) { flags := cmd.NonInheritedFlags() flags.SetOutput(buf) if flags.HasAvailableFlags() { @@ -158,8 +156,6 @@ func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error { parentFlags.PrintDefaults() buf.WriteString("```\n\n") } - - return nil } // Test to see if we have a reason to print See Also information in docs diff --git a/unikraft/app/application.go b/unikraft/app/application.go index 40fa4ab93..4c7dee122 100644 --- a/unikraft/app/application.go +++ b/unikraft/app/application.go @@ -963,11 +963,11 @@ func (app *application) MarshalYAML() (interface{}, error) { // ret["kconfig"] = app.configuration // } - if app.targets != nil && len(app.targets) > 0 { + if len(app.targets) > 0 { ret["targets"] = app.targets } - if app.libraries != nil && len(app.libraries) > 0 { + if len(app.libraries) > 0 { ret["libraries"] = app.libraries } @@ -983,7 +983,7 @@ func (app *application) MarshalYAML() (interface{}, error) { ret["cmd"] = app.command } - if app.volumes != nil && len(app.volumes) > 0 { + if len(app.volumes) > 0 { ret["volumes"] = app.volumes } diff --git a/unikraft/core/core.go b/unikraft/core/core.go index 3e10efffb..6e3afb0dd 100644 --- a/unikraft/core/core.go +++ b/unikraft/core/core.go @@ -259,7 +259,7 @@ func (uc UnikraftConfig) MarshalYAML() (interface{}, error) { "version": uc.version, } - if uc.kconfig != nil && len(uc.kconfig) > 0 { + if len(uc.kconfig) > 0 { ret["kconfig"] = uc.kconfig } diff --git a/unikraft/lib/library.go b/unikraft/lib/library.go index 0823d3720..05d19dc1f 100644 --- a/unikraft/lib/library.go +++ b/unikraft/lib/library.go @@ -559,7 +559,7 @@ func (lc LibraryConfig) MarshalYAML() (interface{}, error) { ret["source"] = lc.source } - if lc.kconfig != nil && len(lc.kconfig) > 0 { + if len(lc.kconfig) > 0 { ret["kconfig"] = lc.kconfig } diff --git a/unikraft/template/template.go b/unikraft/template/template.go index 8df39c619..b39abaedb 100644 --- a/unikraft/template/template.go +++ b/unikraft/template/template.go @@ -101,7 +101,7 @@ func (tc TemplateConfig) MarshalYAML() (interface{}, error) { if len(tc.source) > 0 { ret["source"] = tc.source } - if tc.kconfig != nil && len(tc.kconfig) > 0 { + if len(tc.kconfig) > 0 { ret["kconfig"] = tc.kconfig } if len(ret) == 0 {