From 51fbf3da9ee34a8143df5baeda6032c1747446d2 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 25 Apr 2022 15:15:52 +0200 Subject: enable gocritic linter The linter ensures a common code style. - use switch/case instead of else if - use if instead of switch/case for single case statement - add space between comment and text - detect the use of defer with os.Exit() - use short form var += "..." instead of var = var + "..." - detect problems with append() ``` newSlice := append(orgSlice, val) ``` This could lead to nasty bugs because the orgSlice will be changed in place if it has enough capacity too hold the new elements. Thus we newSlice might not be a copy. Of course most of the changes are just cosmetic and do not cause any logic errors but I think it is a good idea to enforce a common style. This should help maintainability. Signed-off-by: Paul Holzinger --- cmd/podman/common/completion.go | 9 +++++++-- cmd/podman/common/create.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'cmd/podman/common') diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index abb943942..c7d5d6d60 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -327,7 +327,7 @@ func suffixCompSlice(suf string, slice []string) []string { if len(split) > 1 { slice[i] = split[0] + suf + "\t" + split[1] } else { - slice[i] = slice[i] + suf + slice[i] += suf } } return slice @@ -647,7 +647,10 @@ func AutocompleteInspect(cmd *cobra.Command, args []string, toComplete string) ( pods, _ := getPods(cmd, toComplete, completeDefault) networks, _ := getNetworks(cmd, toComplete, completeDefault) volumes, _ := getVolumes(cmd, toComplete) - suggestions := append(containers, images...) + + suggestions := make([]string, 0, len(containers)+len(images)+len(pods)+len(networks)+len(volumes)) + suggestions = append(suggestions, containers...) + suggestions = append(suggestions, images...) suggestions = append(suggestions, pods...) suggestions = append(suggestions, networks...) suggestions = append(suggestions, volumes...) @@ -961,6 +964,8 @@ func AutocompleteFormat(o interface{}) func(cmd *cobra.Command, args []string, t // this function provides shell completion for go templates return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { // autocomplete json when nothing or json is typed + // gocritic complains about the argument order but this is correct in this case + //nolint:gocritic if strings.HasPrefix("json", toComplete) { return []string{"json"}, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 62c9f4c9a..1c1a7c3e3 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -896,7 +896,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions, ) _ = cmd.RegisterFlagCompletionFunc(memorySwappinessFlagName, completion.AutocompleteNone) } - //anyone can use these + // anyone can use these cpusFlagName := "cpus" createFlags.Float64Var( &cf.CPUS, -- cgit v1.2.3-54-g00ecf