From ed73485d92af0329915633d51c7eccdbce9b37cc Mon Sep 17 00:00:00 2001 From: Peter Pan Date: Fri, 12 May 2023 19:24:30 +0800 Subject: [PATCH] chore: make go-lint happy (#405) Signed-off-by: Peter Pan --- cmd/auth/auth.go | 2 +- cmd/auth/new.go | 4 ++-- cmd/filters/filters.go | 2 +- cmd/filters/list.go | 4 ++-- cmd/integration/integration.go | 2 +- cmd/root.go | 3 ++- pkg/analysis/analysis.go | 10 +++++----- pkg/analyzer/node.go | 2 +- pkg/analyzer/pod.go | 2 +- pkg/server/server.go | 2 +- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/auth/auth.go b/cmd/auth/auth.go index 9ae42fc..914139a 100644 --- a/cmd/auth/auth.go +++ b/cmd/auth/auth.go @@ -35,7 +35,7 @@ var AuthCmd = &cobra.Command{ Long: `Provide the necessary credentials to authenticate with your chosen backend.`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { - cmd.Help() + _ = cmd.Help() return } }, diff --git a/cmd/auth/new.go b/cmd/auth/new.go index 9dd1d56..3f1b303 100644 --- a/cmd/auth/new.go +++ b/cmd/auth/new.go @@ -33,8 +33,8 @@ var newCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { backend, _ := cmd.Flags().GetString("backend") if strings.ToLower(backend) == "azureopenai" { - cmd.MarkFlagRequired("engine") - cmd.MarkFlagRequired("baseurl") + _ = cmd.MarkFlagRequired("engine") + _ = cmd.MarkFlagRequired("baseurl") } }, Run: func(cmd *cobra.Command, args []string) { diff --git a/cmd/filters/filters.go b/cmd/filters/filters.go index c5fb30e..a297942 100644 --- a/cmd/filters/filters.go +++ b/cmd/filters/filters.go @@ -25,7 +25,7 @@ var FiltersCmd = &cobra.Command{ You can list available filters to analyze resources.`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { - cmd.Help() + _ = cmd.Help() return } }, diff --git a/cmd/filters/list.go b/cmd/filters/list.go index a5f3442..4f9b08a 100644 --- a/cmd/filters/list.go +++ b/cmd/filters/list.go @@ -37,7 +37,7 @@ var listCmd = &cobra.Command{ activeFilters = coreFilters } inactiveFilters := util.SliceDiff(availableFilters, activeFilters) - fmt.Printf(color.YellowString("Active: \n")) + fmt.Print(color.YellowString("Active: \n")) for _, filter := range activeFilters { // if the filter is an integration, mark this differently @@ -50,7 +50,7 @@ var listCmd = &cobra.Command{ // display inactive filters if len(inactiveFilters) != 0 { - fmt.Printf(color.YellowString("Unused: \n")) + fmt.Print(color.YellowString("Unused: \n")) for _, filter := range inactiveFilters { // if the filter is an integration, mark this differently if util.SliceContainsString(integrationFilters, filter) { diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 1a47140..5c5ffe2 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -32,7 +32,7 @@ var IntegrationCmd = &cobra.Command{ This would allow you to deploy trivy into your cluster and use a K8sGPT analyzer to parse trivy results.`, Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + _ = cmd.Help() }, } diff --git a/cmd/root.go b/cmd/root.go index f09bafd..434f61f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -85,7 +85,7 @@ func initConfig() { viper.SetConfigType("yaml") viper.SetConfigName("k8sgpt") - viper.SafeWriteConfig() + _ = viper.SafeWriteConfig() } viper.Set("kubecontext", kubecontext) @@ -96,6 +96,7 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { + _ = 1 // fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } } diff --git a/pkg/analysis/analysis.go b/pkg/analysis/analysis.go index f496b4d..e199201 100644 --- a/pkg/analysis/analysis.go +++ b/pkg/analysis/analysis.go @@ -141,7 +141,7 @@ func (a *Analysis) RunAnalysis() { results, err := analyzer.Analyze(analyzerConfig) if err != nil { mutex.Lock() - a.Errors = append(a.Errors, fmt.Sprintf(fmt.Sprintf("[%s] %s", reflect.TypeOf(analyzer).Name(), err))) + a.Errors = append(a.Errors, fmt.Sprintf("[%s] %s", reflect.TypeOf(analyzer).Name(), err)) mutex.Unlock() } mutex.Lock() @@ -167,7 +167,7 @@ func (a *Analysis) RunAnalysis() { results, err := analyzer.Analyze(analyzerConfig) if err != nil { mutex.Lock() - a.Errors = append(a.Errors, fmt.Sprintf(fmt.Sprintf("[%s] %s", filter, err))) + a.Errors = append(a.Errors, fmt.Sprintf("[%s] %s", filter, err)) mutex.Unlock() } mutex.Lock() @@ -176,7 +176,7 @@ func (a *Analysis) RunAnalysis() { <-semaphore }(analyzer, filter) } else { - a.Errors = append(a.Errors, fmt.Sprintf(fmt.Sprintf("\"%s\" filter does not exist. Please run k8sgpt filters list.", filter))) + a.Errors = append(a.Errors, fmt.Sprintf("\"%s\" filter does not exist. Please run k8sgpt filters list.", filter)) } } wg.Wait() @@ -234,7 +234,7 @@ func (a *Analysis) GetAIResults(output string, anonymize bool) error { // FIXME: can we avoid checking if output is json multiple times? // maybe implement the progress bar better? if output != "json" { - bar.Exit() + _ = bar.Exit() } // Check for exhaustion @@ -255,7 +255,7 @@ func (a *Analysis) GetAIResults(output string, anonymize bool) error { analysis.Details = parsedText if output != "json" { - bar.Add(1) + _ = bar.Add(1) } a.Results[index] = analysis } diff --git a/pkg/analyzer/node.go b/pkg/analyzer/node.go index ac6f296..af9f1b0 100644 --- a/pkg/analyzer/node.go +++ b/pkg/analyzer/node.go @@ -58,7 +58,7 @@ func (NodeAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { } if len(failures) > 0 { - preAnalysis[fmt.Sprintf("%s", node.Name)] = common.PreAnalysis{ + preAnalysis[node.Name]= common.PreAnalysis{ Node: node, FailureDetails: failures, } diff --git a/pkg/analyzer/pod.go b/pkg/analyzer/pod.go index 7abb92b..cd243ff 100644 --- a/pkg/analyzer/pod.go +++ b/pkg/analyzer/pod.go @@ -85,7 +85,7 @@ func (PodAnalyzer) Analyze(a common.Analyzer) ([]common.Result, error) { } } else { // when pod is Running but its ReadinessProbe fails - if containerStatus.Ready == false && pod.Status.Phase == "Running" { + if !containerStatus.Ready && pod.Status.Phase == "Running" { // parse the event log and append details evt, err := FetchLatestEvent(a.Context, a.Client, pod.Namespace, pod.Name) if err != nil || evt == nil { diff --git a/pkg/server/server.go b/pkg/server/server.go index a22fb3d..b5f5cfc 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -107,7 +107,7 @@ func (s *Config) healthzHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - fmt.Fprintf(w, string(js)) + fmt.Fprint(w, string(js)) } func getBoolParam(param string) bool {