summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-04-25 15:15:52 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-04-26 18:12:22 +0200
commit51fbf3da9ee34a8143df5baeda6032c1747446d2 (patch)
treef5edbd047f5e4aea72b710403a0aa208b238c83b /cmd/podman/common
parent216d9243077f478a9c7ffda1c6e0b1fcbad9ee76 (diff)
downloadpodman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.gz
podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.tar.bz2
podman-51fbf3da9ee34a8143df5baeda6032c1747446d2.zip
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 <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go9
-rw-r--r--cmd/podman/common/create.go2
2 files changed, 8 insertions, 3 deletions
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,