Skip to content

Commit

Permalink
Update golangci-lint for go 1.20
Browse files Browse the repository at this point in the history
Fixes #240

Note that "allow-leading-space" is no longer supported as mentioned in
golangci/golangci-lint#3063 (comment)

Fix new warnings that are now reported.

Signed-off-by: Marc Khouzam <[email protected]>
  • Loading branch information
marckhouzam committed Apr 30, 2023
1 parent 7ad6ce4 commit fa2c943
Show file tree
Hide file tree
Showing 29 changed files with 105 additions and 105 deletions.
11 changes: 4 additions & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ linters-settings:
local-prefixes: github.com/vmware-tanzu
govet:
check-shadowing: true

misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: unused-parameter
disabled: true
whitespace:
multi-func: true

Expand Down Expand Up @@ -144,8 +146,3 @@ run:
skip-dirs:
- fakes/
timeout: 15m

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.46.0 # use the fixed version to not introduce new linters unexpectedly
2 changes: 1 addition & 1 deletion cmd/plugin/builder/command/cli_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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(identifiers)) // nolint:gosec
randSkew := rand.Intn(len(identifiers)) //nolint:gosec
var wg sync.WaitGroup
plugins := make(chan cli.Plugin, len(files))
fatalErrors := make(chan errInfo, len(files))
Expand Down
1 change: 1 addition & 0 deletions cmd/plugin/builder/command/publish/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func convertVersionToStringArray(arrOsArchInfo []osArch) []string {
return oa
}

//nolint:unparam
func createDummyArtifactDir(directoryBasePath, pluginName, recommendedVersion, description string, versions []string) {
var err error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var _ = Describe("Unit tests for inventory plugin-group add", func() {
fakeImgpkgWrapper := &fakes.ImgpkgWrapper{}

// pullDBImageStub create new empty database with the table schemas created
pullDBImageStub := func(image, path string) error {
pullDBImageStub := func(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteDBFileName)
db := plugininventory.NewSQLiteInventory(dbFile, "")
err := db.CreateSchema()
Expand Down
4 changes: 2 additions & 2 deletions cmd/plugin/builder/inventory/inventory_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = Describe("Unit tests for inventory plugin add", func() {
}

// pullDBImageStub create new empty database with the table schemas created
pullDBImageStub := func(image, path string) error {
pullDBImageStub := func(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteDBFileName)
db := plugininventory.NewSQLiteInventory(dbFile, "")
err := db.CreateSchema()
Expand All @@ -46,7 +46,7 @@ var _ = Describe("Unit tests for inventory plugin add", func() {
}

// pullDBImageStubWithPlugins create new database with the table schemas and foo plugin
pullDBImageStubWithPlugins := func(image, path string) error {
pullDBImageStubWithPlugins := func(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteDBFileName)
db := plugininventory.NewSQLiteInventory(dbFile, "")
err := db.CreateSchema()
Expand Down
6 changes: 3 additions & 3 deletions cmd/plugin/builder/inventory_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type inventoryPluginActivateDeactivateFlags struct {

func newInventoryPluginActivateCmd() *cobra.Command {
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 {
Expand All @@ -108,7 +108,7 @@ func newInventoryPluginActivateCmd() *cobra.Command {

func newInventoryPluginDeactivateCmd() *cobra.Command {
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 {
Expand All @@ -126,7 +126,7 @@ func newInventoryPluginDeactivateCmd() *cobra.Command {
return pluginDeactivateCmd
}

func getActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginActivateDeactivateFlags) { // nolint:dupl
func getActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginActivateDeactivateFlags) { //nolint:dupl
var flags = &inventoryPluginActivateDeactivateFlags{}

var activateDeactivateCmd = &cobra.Command{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/builder/inventory_plugin_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func newInventoryPluginGroupDeactivateCmd() *cobra.Command {
return pluginGroupDeactivateCmd
}

func getPluginGroupActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginGroupActivateDeactivateFlags) { // nolint:dupl
func getPluginGroupActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginGroupActivateDeactivateFlags) { //nolint:dupl
var flags = &inventoryPluginGroupActivateDeactivateFlags{}

var activateDeactivateCmd = &cobra.Command{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/builder/template/plugintemplates/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include $(ROOT_DIR_RELATIVE)/plugin-tooling.mk
TOOLS_DIR := tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
GOLANGCI_LINT_VERSION := 1.49.0
GOLANGCI_LINT_VERSION := 1.52.2

.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint the plugin
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BIN_DIR := bin

GOIMPORTS_VERSION=0.1.12
VALE_VERSION=2.20.1
GOLANGCI_LINT_VERSION=1.46.0
GOLANGCI_LINT_VERSION=1.52.2
MISSPELL_VERSION=0.3.4
CONTROLLER_TOOLS_VERSION=0.9.2
IMGPKG_VERSION=v0.35.0
Expand Down
8 changes: 4 additions & 4 deletions pkg/airgapped/plugin_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteDBFileName)
err := utils.SaveFile(dbFile, []byte{})
Expect(err).ToNot(HaveOccurred())
Expand All @@ -175,7 +175,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(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName)
err := utils.SaveFile(dbFile, []byte{})
Expect(err).ToNot(HaveOccurred())
Expand All @@ -189,7 +189,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(image, path string) error { //nolint:unparam
dbFile := filepath.Join(path, plugininventory.SQliteInventoryMetadataDBFileName)
err := utils.SaveFile(dbFile, []byte{})
Expect(err).ToNot(HaveOccurred())
Expand All @@ -208,7 +208,7 @@ imagesToCopy:
}

// copyImageToTarStub fakes the image downloads and creates a fake tar.gz file for images
copyImageToTarStub := func(image, tarfile string) error {
copyImageToTarStub := func(image, tarfile string) error { //nolint:unparam
_, err := os.Create(tarfile)
Expect(err).ToNot(HaveOccurred())
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/csp/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ 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.IsGlobal() { // nolint:staticcheck // Deprecated
if !g.IsGlobal() { //nolint:staticcheck // Deprecated
return nil, fmt.Errorf("trying to fetch token for non global server")
}
if !IsExpired(g.GlobalOpts.Auth.Expiration) {
Expand Down
1 change: 1 addition & 0 deletions pkg/auth/csp/selfmanaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func runLocalListener() error {
mux := http.NewServeMux()
mux.HandleFunc("/callback", callbackHandler)
tokenExchange, tokenExchangeComplete = context.WithCancel(context.TODO())
//nolint:gosec
l := http.Server{
Addr: "",
Handler: mux,
Expand Down
5 changes: 3 additions & 2 deletions pkg/auth/tkg/cluster_pinniped_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tkgauth

import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
Expand Down Expand Up @@ -59,7 +60,7 @@ func GetClusterInfoFromCluster(clusterAPIServerURL, configmapName string) (*clie

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.NewRequestWithContext(context.Background(), "GET", clusterInfoURL, http.NoBody)
// To get the cluster ca certificate first time, we need to use skip verify the server certificate,
// all the later communications to cluster would be using CA after this call
clusterClient := &http.Client{
Expand Down Expand Up @@ -124,7 +125,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.NewRequestWithContext(context.Background(), "GET", pinnipedInfoURL, http.NoBody)
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(clusterInfo.CertificateAuthorityData)
clusterClient := &http.Client{
Expand Down
1 change: 0 additions & 1 deletion pkg/auth/tkg/kube_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func KubeconfigWithPinnipedAuthLoginPlugin(endpoint string, options *KubeConfigO
return
}

mergeFilePath = ""
if options != nil && options.MergeFilePath != "" {
mergeFilePath = options.MergeFilePath
} else {
Expand Down
3 changes: 2 additions & 1 deletion pkg/auth/wcp/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package wcp

import (
"context"
"fmt"
"net/http"

Expand All @@ -22,7 +23,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.NewRequestWithContext(context.Background(), "GET", loginBannerURL, http.NoBody)

resp, err := httpClient.Do(req)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func setUnstableVersions(cfg *configtypes.ClientConfig, value string) error {
configtypes.AlphaUnstableVersions,
configtypes.ExperimentalUnstableVersions,
configtypes.NoUnstableVersions:
cfg.SetUnstableVersionSelector(optionKey) // nolint:staticcheck // Deprecated
cfg.SetUnstableVersionSelector(optionKey) //nolint:staticcheck // Deprecated
default:
return fmt.Errorf("unknown unstable-versions setting: %s; should be one of [all, none, alpha, experimental]", optionKey)
}
Expand All @@ -194,7 +194,7 @@ func setEdition(cfg *configtypes.ClientConfig, edition string) error {

switch editionOption {
case configtypes.EditionCommunity, configtypes.EditionStandard:
cfg.SetEditionSelector(editionOption) // nolint:staticcheck // Deprecated
cfg.SetEditionSelector(editionOption) //nolint:staticcheck // Deprecated
default:
return fmt.Errorf("unknown edition: %s; should be one of [%s, %s]", editionOption, configtypes.EditionStandard, configtypes.EditionCommunity)
}
Expand Down Expand Up @@ -260,9 +260,9 @@ var listServersCmd = &cobra.Command{
}

output := component.NewOutputWriter(cmd.OutOrStdout(), outputFormat, "Name", "Type", "Endpoint", "Path", "Context")
for _, server := range cfg.KnownServers { // nolint:staticcheck // Deprecated
for _, server := range cfg.KnownServers { //nolint:staticcheck // Deprecated
var endpoint, path, context string
if server.IsGlobal() { // nolint:staticcheck // Deprecated
if server.IsGlobal() { //nolint:staticcheck // Deprecated
endpoint = server.GlobalOpts.Endpoint
} else {
endpoint = server.ManagementClusterOpts.Endpoint
Expand Down Expand Up @@ -294,13 +294,13 @@ var deleteServersCmd = &cobra.Command{

if isAborted == nil {
log.Infof("Deleting entry for cluster %s", args[0])
serverExists, err := configlib.ServerExists(args[0]) // nolint:staticcheck // Deprecated
serverExists, err := configlib.ServerExists(args[0]) //nolint:staticcheck // Deprecated
if err != nil {
return err
}

if serverExists {
err := configlib.RemoveServer(args[0]) // nolint:staticcheck // Deprecated
err := configlib.RemoveServer(args[0]) //nolint:staticcheck // Deprecated
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/command/discovery_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func newListDiscoverySourceCmd() *cobra.Command {
}
}
} else {
server, err := configlib.GetCurrentServer() // nolint:staticcheck // Deprecated
server, err := configlib.GetCurrentServer() //nolint:staticcheck // Deprecated
if err == nil && server != nil {
outputFromDiscoverySources(server.DiscoverySources, common.PluginScopeContext, output)
}
Expand Down Expand Up @@ -300,8 +300,8 @@ func createRESTDiscoverySource(discoveryName, uri string) *configtypes.GenericRE

func discoverySourceNameAndType(ds configtypes.PluginDiscovery) (string, string) {
switch {
case ds.GCP != nil: // nolint:staticcheck // Deprecated
return ds.GCP.Name, common.DiscoveryTypeGCP // nolint:staticcheck // Deprecated
case ds.GCP != nil: //nolint:staticcheck // Deprecated
return ds.GCP.Name, common.DiscoveryTypeGCP //nolint:staticcheck // Deprecated
case ds.Kubernetes != nil:
return ds.Kubernetes.Name, common.DiscoveryTypeKubernetes
case ds.Local != nil:
Expand Down
Loading

0 comments on commit fa2c943

Please sign in to comment.