diff --git a/.golangci.yaml b/.golangci.yaml index 6c26724cd..302131348 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -50,8 +50,6 @@ linters-settings: linters: disable-all: true enable: - - deadcode - - depguard - dogsled - dupl - errcheck @@ -67,21 +65,16 @@ linters: - govet - ineffassign - misspell - - nakedret - nolintlint - - revive - staticcheck - stylecheck - typecheck - unconvert - unused - - varcheck - whitespace - bodyclose - noctx - rowserrcheck - - structcheck - - unparam # don't enable: # - asciicheck @@ -99,7 +92,19 @@ linters: # - testpackage # - scopelint # - wsl + # - depguard # This is not being used in the project hence do not enable + # - unparam # TODO: Remove all unused params and re enable the linter + # WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. + # - deadcode + # WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. + # - structcheck + # WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused. + # - varcheck + # TODO: Fix unused-parameters and enable the linters + # - revive + # TODO: Fix naked returns and enable the linters + # - nakedret issues: exclude: - 'declaration of "(err|ctx)" shadows declaration at' @@ -113,6 +118,13 @@ issues: - gocritic - funlen + - linters: + - gosec + text: "G602:" # TODO: Fix disable slice out of bounds issue and re enable the linter + + - linters: + - gosec + text: "G601:" # TODO: Fix Implicit memory aliasing in for loop issue and re enable the linter # https://github.com/go-critic/go-critic/issues/926 - linters: - gocritic diff --git a/cmd/plugin/builder/command/cli_compile.go b/cmd/plugin/builder/command/cli_compile.go index 918700e70..4291519f0 100644 --- a/cmd/plugin/builder/command/cli_compile.go +++ b/cmd/plugin/builder/command/cli_compile.go @@ -126,7 +126,7 @@ func Compile(compileArgs *PluginCompileArgs) error { guard := make(chan struct{}, maxConcurrent) // Mix up IDs so we don't always get the same set. - randSkew := rand.Intn(len(helpers.Identifiers)) // nolint:gosec + randSkew := rand.Intn(len(helpers.Identifiers)) //nolint:gosec var wg sync.WaitGroup plugins := make(chan cli.Plugin, len(files)) fatalErrors := make(chan helpers.ErrInfo, len(files)) diff --git a/cmd/plugin/builder/inventory_plugin.go b/cmd/plugin/builder/inventory_plugin.go index ca1af3208..f0ba03f75 100644 --- a/cmd/plugin/builder/inventory_plugin.go +++ b/cmd/plugin/builder/inventory_plugin.go @@ -90,9 +90,9 @@ type inventoryPluginActivateDeactivateFlags struct { InventoryDBFile string } -func newInventoryPluginActivateCmd() *cobra.Command { // nolint:dupl +func newInventoryPluginActivateCmd() *cobra.Command { //nolint:dupl pluginActivateCmd, flags := getActivateDeactivateBaseCmd() - pluginActivateCmd.Use = "activate" // nolint:goconst + pluginActivateCmd.Use = "activate" //nolint:goconst pluginActivateCmd.Short = "Activate the existing plugin in the inventory database available on the remote repository" pluginActivateCmd.Example = "" pluginActivateCmd.RunE = func(cmd *cobra.Command, args []string) error { @@ -111,9 +111,9 @@ func newInventoryPluginActivateCmd() *cobra.Command { // nolint:dupl return pluginActivateCmd } -func newInventoryPluginDeactivateCmd() *cobra.Command { // nolint:dupl +func newInventoryPluginDeactivateCmd() *cobra.Command { //nolint:dupl pluginDeactivateCmd, flags := getActivateDeactivateBaseCmd() - pluginDeactivateCmd.Use = "deactivate" // nolint:goconst + pluginDeactivateCmd.Use = "deactivate" //nolint:goconst pluginDeactivateCmd.Short = "Deactivate the existing plugin in the inventory database available on the remote repository" pluginDeactivateCmd.Example = "" pluginDeactivateCmd.RunE = func(cmd *cobra.Command, args []string) error { diff --git a/pkg/airgapped/plugin_bundle_test.go b/pkg/airgapped/plugin_bundle_test.go index 4c31f5662..4e7d8d3e7 100644 --- a/pkg/airgapped/plugin_bundle_test.go +++ b/pkg/airgapped/plugin_bundle_test.go @@ -208,7 +208,7 @@ imagesToCopy: // downloadInventoryImageAndSaveFilesToDirStub fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryImageAndSaveFilesToDirStub := func(image, path string) error { + downloadInventoryImageAndSaveFilesToDirStub := func(_, path string) error { dbFile := filepath.Join(path, plugininventory.SQliteDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -233,7 +233,7 @@ imagesToCopy: // downloadInventoryMetadataImageWithNoExistingPlugins fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryMetadataImageWithNoExistingPlugins := func(image, path string) error { + downloadInventoryMetadataImageWithNoExistingPlugins := func(_, path string) error { dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -247,7 +247,7 @@ imagesToCopy: // downloadInventoryMetadataImageWithExistingPlugins fakes the image downloads and puts a database // with the table schemas created to provided path - downloadInventoryMetadataImageWithExistingPlugins := func(image, path string) error { + downloadInventoryMetadataImageWithExistingPlugins := func(_, path string) error { dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName) err := utils.SaveFile(dbFile, []byte{}) Expect(err).ToNot(HaveOccurred()) @@ -272,7 +272,7 @@ imagesToCopy: } // copyImageToTarStub fakes the image downloads and creates a fake tar.gz file for images - copyImageToTarStub := func(image, tarfile string) error { + copyImageToTarStub := func(_, tarfile string) error { _, err := os.Create(tarfile) Expect(err).ToNot(HaveOccurred()) return nil diff --git a/pkg/auth/csp/grpc.go b/pkg/auth/csp/grpc.go index f39b4705a..bb4dfbf7c 100644 --- a/pkg/auth/csp/grpc.go +++ b/pkg/auth/csp/grpc.go @@ -62,14 +62,14 @@ type configSource struct { // Token fetches the token. func (c *configSource) Token() (*oauth2.Token, error) { - g, err := c.GetCurrentServer() // nolint:staticcheck // Deprecated + g, err := c.GetCurrentServer() //nolint:staticcheck // Deprecated if err != nil { return nil, err } if g == nil { return nil, fmt.Errorf("current server is nil") } - if !g.IsGlobal() { // nolint:staticcheck // Deprecated + if !g.IsGlobal() { //nolint:staticcheck // Deprecated return nil, fmt.Errorf("trying to fetch token for non global server") } var expiration time.Time diff --git a/pkg/auth/csp/selfmanaged.go b/pkg/auth/csp/selfmanaged.go index fec8a3455..1fe66f978 100644 --- a/pkg/auth/csp/selfmanaged.go +++ b/pkg/auth/csp/selfmanaged.go @@ -96,6 +96,7 @@ func runLocalListener() error { mux := http.NewServeMux() mux.HandleFunc("/callback", callbackHandler) tokenExchange, tokenExchangeComplete = context.WithCancel(context.TODO()) + //nolint:gosec //G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec) l := http.Server{ Addr: "", Handler: mux, diff --git a/pkg/auth/tkg/cluster_pinniped_info.go b/pkg/auth/tkg/cluster_pinniped_info.go index 83af30def..4288e9b65 100644 --- a/pkg/auth/tkg/cluster_pinniped_info.go +++ b/pkg/auth/tkg/cluster_pinniped_info.go @@ -60,7 +60,7 @@ func GetClusterInfoFromCluster(clusterAPIServerURL, configmapName, endpointCACer clusterAPIServerURL = strings.TrimRight(clusterAPIServerURL, " /") clusterInfoURL := clusterAPIServerURL + fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", KubePublicNamespace, configmapName) - req, _ := http.NewRequest("GET", clusterInfoURL, http.NoBody) + req, _ := http.NewRequest("GET", clusterInfoURL, http.NoBody) //nolint:noctx //should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx) tlsConfig, err := GetTLSConfig(endpointCACertPath, skipTLSVerify) if err != nil { @@ -126,7 +126,7 @@ func GetPinnipedInfoFromCluster(clusterInfo *clientcmdapi.Cluster, discoveryPort } } pinnipedInfoURL := endpoint + fmt.Sprintf("/api/v1/namespaces/%s/configmaps/pinniped-info", KubePublicNamespace) - req, _ := http.NewRequest("GET", pinnipedInfoURL, http.NoBody) + req, _ := http.NewRequest("GET", pinnipedInfoURL, http.NoBody) //nolint:noctx //should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx) pool := x509.NewCertPool() pool.AppendCertsFromPEM(clusterInfo.CertificateAuthorityData) clusterClient := &http.Client{ @@ -187,7 +187,7 @@ func GetTLSConfig(caCertPath string, skipTLSVerify bool) (*tls.Config, error) { return &tls.Config{ RootCAs: pool, MinVersion: tls.VersionTLS12, - // nolint:gosec + //nolint:gosec // skipTLSVerify: true is only possible if the user has explicitly enabled insecure-skip-tls-verify. InsecureSkipVerify: skipTLSVerify, }, nil diff --git a/pkg/auth/tkg/kube_config.go b/pkg/auth/tkg/kube_config.go index 24f4a2905..9c5649ca9 100644 --- a/pkg/auth/tkg/kube_config.go +++ b/pkg/auth/tkg/kube_config.go @@ -208,7 +208,6 @@ func TanzuLocalKubeConfigPath() (path string, err error) { } func MergeAndSaveKubeconfigBytes(kubeconfigBytes []byte, options *KubeConfigOptions) (mergeFilePath, currentContext string, err error) { - mergeFilePath = "" if options != nil && options.MergeFilePath != "" { mergeFilePath = options.MergeFilePath } else { diff --git a/pkg/auth/wcp/discovery.go b/pkg/auth/wcp/discovery.go index 4aa4e9420..90aeb2a09 100644 --- a/pkg/auth/wcp/discovery.go +++ b/pkg/auth/wcp/discovery.go @@ -22,7 +22,7 @@ const ( func IsVSphereSupervisor(endpoint string, httpClient *http.Client) (bool, error) { loginBannerURL := fmt.Sprintf("%s/wcp/loginbanner", endpoint) - req, _ := http.NewRequest("GET", loginBannerURL, http.NoBody) + req, _ := http.NewRequest("GET", loginBannerURL, http.NoBody) //nolint:noctx //should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx) resp, err := httpClient.Do(req) if err != nil { diff --git a/pkg/command/login.go b/pkg/command/login.go index 134cdc787..fb2f1ce2d 100644 --- a/pkg/command/login.go +++ b/pkg/command/login.go @@ -51,9 +51,9 @@ func init() { loginCmd.Flags().BoolVar(&staging, "staging", false, "use CSP staging issuer") loginCmd.Flags().StringVar(&endpointCACertPath, "endpoint-ca-certificate", "", "path to the endpoint public certificate") loginCmd.Flags().BoolVar(&skipTLSVerify, "insecure-skip-tls-verify", false, "skip endpoint's TLS certificate verification") - loginCmd.Flags().MarkHidden("stderr-only") // nolint - loginCmd.Flags().MarkHidden("force-csp") // nolint - loginCmd.Flags().MarkHidden("staging") // nolint + loginCmd.Flags().MarkHidden("stderr-only") //nolint + loginCmd.Flags().MarkHidden("force-csp") //nolint + loginCmd.Flags().MarkHidden("staging") //nolint loginCmd.SetUsageFunc(cli.SubCmdUsageFunc) loginCmd.MarkFlagsMutuallyExclusive("endpoint-ca-certificate", "insecure-skip-tls-verify") @@ -94,7 +94,7 @@ func login(cmd *cobra.Command, args []string) (err error) { } newServerSelector := "+ new server" - var serverTarget *configtypes.Server // nolint:staticcheck // Deprecated + var serverTarget *configtypes.Server //nolint:staticcheck // Deprecated if name != "" { serverTarget, err = createNewServer() if err != nil { @@ -106,7 +106,7 @@ func login(cmd *cobra.Command, args []string) (err error) { return err } } else { - serverTarget, err = config.GetServer(server) // nolint:staticcheck // Deprecated + serverTarget, err = config.GetServer(server) //nolint:staticcheck // Deprecated if err != nil { return err } @@ -119,7 +119,7 @@ func login(cmd *cobra.Command, args []string) (err error) { } } - if serverTarget.Type == configtypes.GlobalServerType { // nolint:staticcheck // Deprecated + if serverTarget.Type == configtypes.GlobalServerType { //nolint:staticcheck // Deprecated err = globalLoginUsingServer(serverTarget) } else { err = managementClusterLogin(serverTarget) @@ -137,11 +137,11 @@ func login(cmd *cobra.Command, args []string) (err error) { return nil } -func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (*configtypes.Server, error) { // nolint:staticcheck // Deprecated +func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (*configtypes.Server, error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() - servers := map[string]*configtypes.Server{} // nolint:staticcheck // Deprecated - for _, server := range cfg.KnownServers { // nolint:staticcheck // Deprecated - ep, err := config.EndpointFromServer(server) // nolint:staticcheck // Deprecated + servers := map[string]*configtypes.Server{} //nolint:staticcheck // Deprecated + for _, server := range cfg.KnownServers { //nolint:staticcheck // Deprecated + ep, err := config.EndpointFromServer(server) //nolint:staticcheck // Deprecated if err != nil { return nil, err } @@ -159,7 +159,7 @@ func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (* } serverKeys := getKeysFromServerMap(servers) serverKeys = append(serverKeys, newServerSelector) - servers[newServerSelector] = &configtypes.Server{} // nolint:staticcheck // Deprecated + servers[newServerSelector] = &configtypes.Server{} //nolint:staticcheck // Deprecated err := component.Prompt( &component.PromptConfig{ Message: "Select a server", @@ -175,7 +175,7 @@ func getServerTarget(cfg *configtypes.ClientConfig, newServerSelector string) (* return servers[server], nil } -func getKeysFromServerMap(m map[string]*configtypes.Server) []string { // nolint:staticcheck // Deprecated +func getKeysFromServerMap(m map[string]*configtypes.Server) []string { //nolint:staticcheck // Deprecated keys := make([]string, 0, len(m)) for key := range m { keys = append(keys, key) @@ -194,7 +194,7 @@ func isGlobalServer(endpoint string) bool { return false } -func createNewServer() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createNewServer() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated // user provided command line options to create a server using kubeconfig[optional] and context if kubeContext != "" { return createServerWithKubeconfig() @@ -227,7 +227,7 @@ func createNewServer() (server *configtypes.Server, err error) { // nolint:stati return createServerWithKubeconfig() } -func createServerWithKubeconfig() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createServerWithKubeconfig() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() if kubeConfig == "" && kubeContext == "" { err = component.Prompt( @@ -272,7 +272,7 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n } } name = strings.TrimSpace(name) - nameExists, err := config.ServerExists(name) // nolint:staticcheck // Deprecated + nameExists, err := config.ServerExists(name) //nolint:staticcheck // Deprecated if err != nil { return server, err } @@ -281,12 +281,12 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n return } - endpointType := configtypes.ManagementClusterServerType // nolint:staticcheck // Deprecated + endpointType := configtypes.ManagementClusterServerType //nolint:staticcheck // Deprecated - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, Type: endpointType, - ManagementClusterOpts: &configtypes.ManagementClusterServer{ // nolint:staticcheck // Deprecated + ManagementClusterOpts: &configtypes.ManagementClusterServer{ //nolint:staticcheck // Deprecated Path: kubeConfig, Context: kubeContext, Endpoint: endpoint}, @@ -294,7 +294,7 @@ func createServerWithKubeconfig() (server *configtypes.Server, err error) { // n return server, err } -func createServerWithEndpoint() (server *configtypes.Server, err error) { // nolint:staticcheck // Deprecated +func createServerWithEndpoint() (server *configtypes.Server, err error) { //nolint:staticcheck // Deprecated promptOpts := getPromptOpts() if endpoint == "" { err = component.Prompt( @@ -322,7 +322,7 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol } } name = strings.TrimSpace(name) - nameExists, err := config.ServerExists(name) // nolint:staticcheck // Deprecated + nameExists, err := config.ServerExists(name) //nolint:staticcheck // Deprecated if err != nil { return server, err } @@ -331,9 +331,9 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol return } if isGlobalServer(endpoint) { - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, - Type: configtypes.GlobalServerType, // nolint:staticcheck // Deprecated + Type: configtypes.GlobalServerType, //nolint:staticcheck // Deprecated GlobalOpts: &configtypes.GlobalServer{Endpoint: sanitizeEndpoint(endpoint)}, } } else { @@ -343,10 +343,10 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol return } - server = &configtypes.Server{ // nolint:staticcheck // Deprecated + server = &configtypes.Server{ //nolint:staticcheck // Deprecated Name: name, - Type: configtypes.ManagementClusterServerType, // nolint:staticcheck // Deprecated - ManagementClusterOpts: &configtypes.ManagementClusterServer{ // nolint:staticcheck // Deprecated + Type: configtypes.ManagementClusterServerType, //nolint:staticcheck // Deprecated + ManagementClusterOpts: &configtypes.ManagementClusterServer{ //nolint:staticcheck // Deprecated Path: kubeConfig, Context: kubeContext, Endpoint: endpoint}, @@ -355,7 +355,7 @@ func createServerWithEndpoint() (server *configtypes.Server, err error) { // nol return server, err } -func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:staticcheck // Deprecated +func globalLoginUsingServer(s *configtypes.Server) (err error) { //nolint:staticcheck // Deprecated a := configtypes.GlobalServerAuth{} apiTokenValue, apiTokenExists := os.LookupEnv(config.EnvAPITokenKey) @@ -396,7 +396,7 @@ func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:stati s.GlobalOpts.Auth = a } - err = config.PutServer(s, true) // nolint:staticcheck // Deprecated + err = config.PutServer(s, true) //nolint:staticcheck // Deprecated if err != nil { return err } @@ -406,7 +406,7 @@ func globalLoginUsingServer(s *configtypes.Server) (err error) { // nolint:stati return nil } -func managementClusterLogin(s *configtypes.Server) error { // nolint:staticcheck // Deprecated +func managementClusterLogin(s *configtypes.Server) error { //nolint:staticcheck // Deprecated if s != nil && s.ManagementClusterOpts != nil && s.ManagementClusterOpts.Path != "" && s.ManagementClusterOpts.Context != "" { _, err := tkgauth.GetServerKubernetesVersion(s.ManagementClusterOpts.Path, s.ManagementClusterOpts.Context) if err != nil { @@ -414,7 +414,7 @@ func managementClusterLogin(s *configtypes.Server) error { // nolint:staticcheck log.Error(err, "") return err } - err = config.PutServer(s, true) // nolint:staticcheck // Deprecated + err = config.PutServer(s, true) //nolint:staticcheck // Deprecated if err != nil { return err } diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index 82cd1d853..44190ff22 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -41,13 +41,13 @@ const CoreRepositoryName = "core" var CoreBucketName = "tanzu-cli-framework" // DefaultVersionSelector is to only use stable versions of plugins -const DefaultVersionSelector = configtypes.NoUnstableVersions // nolint:staticcheck // Deprecated +const DefaultVersionSelector = configtypes.NoUnstableVersions //nolint:staticcheck // Deprecated // DefaultEdition is the edition assumed when there is no value in the local config file const DefaultEdition = "tkg" // CoreGCPBucketRepository is the default GCP bucket repository. -var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticcheck // Deprecated +var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ //nolint:staticcheck // Deprecated BucketName: CoreBucketName, Name: CoreRepositoryName, } @@ -56,7 +56,7 @@ var CoreGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticc const AdvancedRepositoryName = "advanced" // AdvancedGCPBucketRepository is the GCP bucket repository for advanced plugins. -var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:staticcheck // Deprecated +var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ //nolint:staticcheck // Deprecated BucketName: "tanzu-cli-advanced-plugins", Name: AdvancedRepositoryName, } @@ -65,7 +65,7 @@ var AdvancedGCPBucketRepository = configtypes.GCPPluginRepository{ // nolint:sta const DefaultTMCPluginsArtifactRepository = "https://tmc-cli.s3-us-west-2.amazonaws.com/plugins/artifacts" // DefaultRepositories are the default repositories for the CLI. -var DefaultRepositories = []configtypes.PluginRepository{ // nolint:staticcheck // Deprecated +var DefaultRepositories = []configtypes.PluginRepository{ //nolint:staticcheck // Deprecated { GCPPluginRepository: &CoreGCPBucketRepository, }, @@ -179,7 +179,7 @@ func GetAdditionalTestDiscoveryImages() []string { return additionalImages } -func getHTTPURIForGCPPluginRepository(repo configtypes.GCPPluginRepository) string { // nolint:staticcheck // Deprecated +func getHTTPURIForGCPPluginRepository(repo configtypes.GCPPluginRepository) string { //nolint:staticcheck // Deprecated return fmt.Sprintf("https://storage.googleapis.com/%s/", repo.BucketName) } diff --git a/pkg/discovery/utils.go b/pkg/discovery/utils.go index d7b8ac784..d970bd708 100644 --- a/pkg/discovery/utils.go +++ b/pkg/discovery/utils.go @@ -10,7 +10,7 @@ import ( // CheckDiscoveryName returns true if discovery name exists else return false func CheckDiscoveryName(ds configtypes.PluginDiscovery, dn string) bool { - return (ds.GCP != nil && ds.GCP.Name == dn) || // nolint:staticcheck // Deprecated + return (ds.GCP != nil && ds.GCP.Name == dn) || //nolint:staticcheck // Deprecated (ds.Kubernetes != nil && ds.Kubernetes.Name == dn) || (ds.Local != nil && ds.Local.Name == dn) || (ds.REST != nil && ds.REST.Name == dn) || @@ -39,10 +39,10 @@ func CompareDiscoverySource(ds1, ds2 configtypes.PluginDiscovery, dsType string) } func compareGCPDiscoverySources(ds1, ds2 configtypes.PluginDiscovery) bool { - return ds1.GCP != nil && ds2.GCP != nil && // nolint:staticcheck // Deprecated - ds1.GCP.Name == ds2.GCP.Name && // nolint:staticcheck // Deprecated - ds1.GCP.Bucket == ds2.GCP.Bucket && // nolint:staticcheck // Deprecated - ds1.GCP.ManifestPath == ds2.GCP.ManifestPath // nolint:staticcheck // Deprecated + return ds1.GCP != nil && ds2.GCP != nil && //nolint:staticcheck // Deprecated + ds1.GCP.Name == ds2.GCP.Name && //nolint:staticcheck // Deprecated + ds1.GCP.Bucket == ds2.GCP.Bucket && //nolint:staticcheck // Deprecated + ds1.GCP.ManifestPath == ds2.GCP.ManifestPath //nolint:staticcheck // Deprecated } func compareLocalDiscoverySources(ds1, ds2 configtypes.PluginDiscovery) bool { diff --git a/pkg/plugininventory/sqlite_inventory_test.go b/pkg/plugininventory/sqlite_inventory_test.go index af36b7dcf..d65a07d9e 100644 --- a/pkg/plugininventory/sqlite_inventory_test.go +++ b/pkg/plugininventory/sqlite_inventory_test.go @@ -504,7 +504,7 @@ var _ = Describe("Unit tests for plugin inventory", func() { Expect(len(plugins)).To(Equal(2)) for _, p := range plugins { - if p.Name == "management-cluster" { // nolint: goconst + if p.Name == "management-cluster" { //nolint: goconst Expect(p.RecommendedVersion).To(Equal("v0.28.0")) Expect(string(p.Target)).To(Equal("kubernetes")) Expect(p.Description).To(Equal("Kubernetes management cluster operations")) @@ -515,7 +515,7 @@ var _ = Describe("Unit tests for plugin inventory", func() { artifactList := p.Artifacts["v0.28.0"] Expect(len(artifactList)).To(Equal(2)) for _, a := range artifactList { - if a.OS == "linux" { // nolint: goconst + if a.OS == "linux" { //nolint: goconst Expect(a.Arch).To(Equal("amd64")) Expect(a.Digest).To(Equal("0000000000")) Expect(a.Image).To(Equal(tmpDir + "/vmware/tkg/linux/amd64/k8s/management-cluster:v0.28.0")) diff --git a/pkg/pluginmanager/default_discoveries.go b/pkg/pluginmanager/default_discoveries.go index 22770bbac..8dfc3d67e 100644 --- a/pkg/pluginmanager/default_discoveries.go +++ b/pkg/pluginmanager/default_discoveries.go @@ -16,12 +16,12 @@ const True = "true" const HTTPS = "https" const HTTP = "http" -func defaultDiscoverySourceBasedOnServer(server *configtypes.Server) []configtypes.PluginDiscovery { // nolint:staticcheck // Deprecated +func defaultDiscoverySourceBasedOnServer(server *configtypes.Server) []configtypes.PluginDiscovery { //nolint:staticcheck // Deprecated var defaultDiscoveries []configtypes.PluginDiscovery // If current server type is management-cluster, then add // the default kubernetes discovery endpoint pointing to the // management-cluster kubeconfig - if server != nil && server.Type == configtypes.ManagementClusterServerType && server.ManagementClusterOpts != nil { // nolint:staticcheck // Deprecated + if server != nil && server.Type == configtypes.ManagementClusterServerType && server.ManagementClusterOpts != nil { //nolint:staticcheck // Deprecated defaultDiscoveries = append(defaultDiscoveries, defaultDiscoverySourceForK8sTargetedContext(server.Name, server.ManagementClusterOpts.Path, server.ManagementClusterOpts.Context)) } return defaultDiscoveries diff --git a/pkg/pluginmanager/manager.go b/pkg/pluginmanager/manager.go index 319d08b43..54d60bacb 100644 --- a/pkg/pluginmanager/manager.go +++ b/pkg/pluginmanager/manager.go @@ -446,7 +446,8 @@ func InstallPluginFromContext(pluginName, version string, target configtypes.Tar // installs a plugin by name, version and target. // If the contextName is not empty, it implies the plugin is a context-scope plugin, otherwise // we are installing a standalone plugin. -// nolint: gocyclo +// +//nolint:gocyclo func installPlugin(pluginName, version string, target configtypes.Target, contextName string) error { discoveries, err := getPluginDiscoveries() if err != nil { @@ -962,7 +963,8 @@ func SyncPlugins() error { } // InstallPluginsFromLocalSource installs plugin from local source directory -// nolint: gocyclo +// +//nolint:gocyclo func InstallPluginsFromLocalSource(pluginName, version string, target configtypes.Target, localPath string, installTestPlugin bool) error { // Set default local plugin distro to local-path as while installing the plugin // from local source we should take t diff --git a/pkg/registry/client.go b/pkg/registry/client.go index ba211c1ef..570b775aa 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -104,7 +104,7 @@ func getFilesFromLayer(imgLayer regv1.Layer) (map[string][]byte, error) { } return files, err } - if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA { + if hdr.Typeflag == tar.TypeReg || hdr.Typeflag == tar.TypeRegA { //nolint:staticcheck //SA1019: tar.TypeRegA has been deprecated since Go 1.11 and an alternative has been available since Go 1.1: Use TypeReg instead. (staticcheck) buf, err := io.ReadAll(tarReader) if err != nil { return files, err diff --git a/pkg/telemetry/sqlite_metrics_db.go b/pkg/telemetry/sqlite_metrics_db.go index 849e584ee..efc1c7e69 100644 --- a/pkg/telemetry/sqlite_metrics_db.go +++ b/pkg/telemetry/sqlite_metrics_db.go @@ -148,7 +148,8 @@ func (b *sqliteMetricsDB) GetRowCount() (int, error) { defer db.Close() dbQuery := cliOperationMetricRowClause - rows, err := db.Query(dbQuery) + rows, err := db.Query(dbQuery) //nolint:rowserrcheck // rows.Err must be checked (rowserrcheck) + if err != nil { return 0, errors.Wrapf(err, "failed to execute the DB query : %v", dbQuery) } @@ -161,7 +162,7 @@ func (b *sqliteMetricsDB) GetRowCount() (int, error) { } func isDBRowCountThresholdReached(db *sql.DB) (bool, error) { dbQuery := cliOperationMetricRowClause - rows, err := db.Query(dbQuery) + rows, err := db.Query(dbQuery) //nolint:rowserrcheck // rows.Err must be checked (rowserrcheck) if err != nil { return false, errors.Wrapf(err, "failed to execute the DB query : %v", dbQuery) } diff --git a/pkg/telemetry/sqlite_metrics_db_test.go b/pkg/telemetry/sqlite_metrics_db_test.go index 73dd9c30f..b8888cdc9 100644 --- a/pkg/telemetry/sqlite_metrics_db_test.go +++ b/pkg/telemetry/sqlite_metrics_db_test.go @@ -100,7 +100,7 @@ func getOperationMetrics(metricsDB *sqliteMetricsDB) ([]*cliOperationsRow, error defer db.Close() dbQuery := selectAllFromCLIOperationMetrics - rows, err := db.Query(dbQuery) + rows, err := db.Query(dbQuery) //nolint:rowserrcheck // rows.Err must be checked (rowserrcheck) if err != nil { return nil, errors.Wrapf(err, "failed to execute the DB query : %v", dbQuery) }