Skip to content

Commit

Permalink
fix: Lint problems reported by new tools
Browse files Browse the repository at this point in the history
Signed-off-by: Cezar Craciunoiu <[email protected]>
  • Loading branch information
craciunoiuc committed Nov 27, 2024
1 parent 8b072c5 commit e85a04e
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/cli/kraft/cloud/volume/import/cpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/kraft/compose/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/yamlmerger/yamlmerger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 6 additions & 8 deletions libmocktainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -507,7 +505,7 @@ func (c *Container) currentState() (*State, error) {
}
}
}
return state, nil
return state
}

func (c *Container) currentOCIState() (*specs.State, error) {
Expand Down
2 changes: 1 addition & 1 deletion machine/qemu/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions tools/gendocs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions unikraft/app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion unikraft/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion unikraft/lib/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion unikraft/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e85a04e

Please sign in to comment.