diff --git a/.golangci.yaml b/.golangci.yaml index 7e0e9926cf..828a099a40 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,4 +1,15 @@ --- +linters: + disable-all: true + enable: + - errcheck + - gofmt + - goimports + - govet + - staticcheck + - unparam + - unused + issues: exclude: - SA1006 # printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) diff --git a/Makefile b/Makefile index dc8e486d0c..128beec005 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,6 @@ endif # chcon -Rt svirt_sandbox_file_t . # chcon -Rt svirt_sandbox_file_t ~/.cache/golangci-lint lint: - go fmt ./... - go vet -tags "fixtures acceptance" ./... $(RUNNER) run -t --rm \ -v $(shell pwd):/app \ -v ~/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION):/root/.cache \ diff --git a/internal/acceptance/openstack/identity/v3/oauth1_test.go b/internal/acceptance/openstack/identity/v3/oauth1_test.go index 58e71daf27..da6c8be148 100644 --- a/internal/acceptance/openstack/identity/v3/oauth1_test.go +++ b/internal/acceptance/openstack/identity/v3/oauth1_test.go @@ -93,11 +93,11 @@ func TestOAuth1CRUD(t *testing.T) { // test HMACSHA1 and PLAINTEXT signature methods for _, method := range []oauth1.SignatureMethod{oauth1.HMACSHA1, oauth1.PLAINTEXT} { - oauth1MethodTest(t, client, consumer, method, user, project, roles, ao.IdentityEndpoint) + oauth1MethodTest(t, client, consumer, method, user, project, roles) } } -func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role, identityEndpoint string) { +func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role) { // Request a token requestTokenOpts := oauth1.RequestTokenOpts{ OAuthConsumerKey: consumer.ID, diff --git a/internal/acceptance/openstack/networking/v2/extensions/layer3/l3_scheduling_test.go b/internal/acceptance/openstack/networking/v2/extensions/layer3/l3_scheduling_test.go index ed110dfff4..f186118d44 100644 --- a/internal/acceptance/openstack/networking/v2/extensions/layer3/l3_scheduling_test.go +++ b/internal/acceptance/openstack/networking/v2/extensions/layer3/l3_scheduling_test.go @@ -54,7 +54,7 @@ func TestLayer3RouterScheduling(t *testing.T) { containsRouterFunc := func(rs []routers.Router, routerID string) bool { for _, r := range rs { - if r.ID == router.ID { + if r.ID == routerID { return true } } diff --git a/internal/acceptance/openstack/sharedfilesystems/v2/replicas.go b/internal/acceptance/openstack/sharedfilesystems/v2/replicas.go index f9ab7e9827..6a2d31d08a 100644 --- a/internal/acceptance/openstack/sharedfilesystems/v2/replicas.go +++ b/internal/acceptance/openstack/sharedfilesystems/v2/replicas.go @@ -28,7 +28,7 @@ func CreateReplica(t *testing.T, client *gophercloud.ServiceClient, share *share return nil, err } - _, err = waitForReplicaStatus(t, client, replica.ID, "available") + err = waitForReplicaStatus(t, client, replica.ID, "available") if err != nil { t.Logf("Failed to get %s replica status", replica.ID) DeleteReplica(t, client, replica) @@ -49,7 +49,7 @@ func DeleteReplica(t *testing.T, client *gophercloud.ServiceClient, replica *rep t.Errorf("Unable to delete replica %s: %v", replica.ID, err) } - _, err = waitForReplicaStatus(t, client, replica.ID, "deleted") + err = waitForReplicaStatus(t, client, replica.ID, "deleted") if err != nil { t.Errorf("Failed to wait for 'deleted' status for %s replica: %v", replica.ID, err) } else { @@ -71,7 +71,7 @@ func ListShareReplicas(t *testing.T, client *gophercloud.ServiceClient, shareID return replicas.ExtractReplicas(pages) } -func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status string) (*replicas.Replica, error) { +func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status string) error { var current *replicas.Replica err := tools.WaitFor(func(ctx context.Context) (bool, error) { @@ -104,14 +104,14 @@ func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status if err != nil { mErr := PrintMessages(t, c, id) if mErr != nil { - return current, fmt.Errorf("Replica status is '%s' and unable to get manila messages: %s", err, mErr) + return fmt.Errorf("Replica status is '%s' and unable to get manila messages: %s", err, mErr) } } - return current, err + return err } -func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state string) (*replicas.Replica, error) { +func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state string) error { var current *replicas.Replica err := tools.WaitFor(func(ctx context.Context) (bool, error) { @@ -136,9 +136,9 @@ func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state s if err != nil { mErr := PrintMessages(t, c, id) if mErr != nil { - return current, fmt.Errorf("Replica state is '%s' and unable to get manila messages: %s", err, mErr) + return fmt.Errorf("Replica state is '%s' and unable to get manila messages: %s", err, mErr) } } - return current, err + return err } diff --git a/internal/acceptance/openstack/sharedfilesystems/v2/replicas_test.go b/internal/acceptance/openstack/sharedfilesystems/v2/replicas_test.go index 0d564c95e0..41913ac266 100644 --- a/internal/acceptance/openstack/sharedfilesystems/v2/replicas_test.go +++ b/internal/acceptance/openstack/sharedfilesystems/v2/replicas_test.go @@ -86,7 +86,7 @@ func TestReplicaPromote(t *testing.T) { // sync new replica err = replicas.Resync(context.TODO(), client, created.ID).ExtractErr() th.AssertNoErr(t, err) - _, err = waitForReplicaState(t, client, created.ID, "in_sync") + err = waitForReplicaState(t, client, created.ID, "in_sync") if err != nil { t.Fatalf("Replica status error: %v", err) } @@ -95,7 +95,7 @@ func TestReplicaPromote(t *testing.T) { err = replicas.Promote(context.TODO(), client, created.ID, &replicas.PromoteOpts{}).ExtractErr() th.AssertNoErr(t, err) - _, err = waitForReplicaState(t, client, created.ID, "active") + err = waitForReplicaState(t, client, created.ID, "active") if err != nil { t.Fatalf("Replica status error: %v", err) } @@ -117,14 +117,14 @@ func TestReplicaPromote(t *testing.T) { // sync old replica err = replicas.Resync(context.TODO(), client, oldReplicaID).ExtractErr() th.AssertNoErr(t, err) - _, err = waitForReplicaState(t, client, oldReplicaID, "in_sync") + err = waitForReplicaState(t, client, oldReplicaID, "in_sync") if err != nil { t.Fatalf("Replica status error: %v", err) } err = replicas.Promote(context.TODO(), client, oldReplicaID, &replicas.PromoteOpts{}).ExtractErr() th.AssertNoErr(t, err) - _, err = waitForReplicaState(t, client, oldReplicaID, "active") + err = waitForReplicaState(t, client, oldReplicaID, "active") if err != nil { t.Fatalf("Replica status error: %v", err) } @@ -262,7 +262,7 @@ func TestReplicaResetStatus(t *testing.T) { } // We need to wait till the Extend operation is done - _, err = waitForReplicaStatus(t, client, replica.ID, "error") + err = waitForReplicaStatus(t, client, replica.ID, "error") if err != nil { t.Fatalf("Replica status error: %v", err) } @@ -300,7 +300,7 @@ func TestReplicaForceDelete(t *testing.T) { t.Fatalf("Unable to force delete a replica: %v", err) } - _, err = waitForReplicaStatus(t, client, replica.ID, "deleted") + err = waitForReplicaStatus(t, client, replica.ID, "deleted") if err != nil { t.Fatalf("Replica status error: %v", err) } diff --git a/openstack/networking/v2/extensions/bgp/speakers/testing/requests_test.go b/openstack/networking/v2/extensions/bgp/speakers/testing/requests_test.go index 8f77107607..9e8df52b0c 100644 --- a/openstack/networking/v2/extensions/bgp/speakers/testing/requests_test.go +++ b/openstack/networking/v2/extensions/bgp/speakers/testing/requests_test.go @@ -224,9 +224,9 @@ func TestGetAdvertisedRoutes(t *testing.T) { } expected := []speakers.AdvertisedRoute{ - speakers.AdvertisedRoute{NextHop: "172.17.128.212", Destination: "172.17.129.192/27"}, - speakers.AdvertisedRoute{NextHop: "172.17.128.218", Destination: "172.17.129.0/27"}, - speakers.AdvertisedRoute{NextHop: "172.17.128.231", Destination: "172.17.129.160/27"}, + {NextHop: "172.17.128.212", Destination: "172.17.129.192/27"}, + {NextHop: "172.17.128.218", Destination: "172.17.129.0/27"}, + {NextHop: "172.17.128.231", Destination: "172.17.129.160/27"}, } th.CheckDeepEquals(t, count, 1) th.CheckDeepEquals(t, expected, actual) diff --git a/openstack/objectstorage/v1/objects/requests.go b/openstack/objectstorage/v1/objects/requests.go index ca462a061f..abc56f4773 100644 --- a/openstack/objectstorage/v1/objects/requests.go +++ b/openstack/objectstorage/v1/objects/requests.go @@ -596,10 +596,7 @@ func CreateTempURL(ctx context.Context, c *gophercloud.ServiceClient, containerN if err != nil { return "", err } - urlToBeSigned, err := tempURL(c, containerName, objectName) - if err != nil { - return "", err - } + urlToBeSigned := tempURL(c, containerName, objectName) if opts.Split == "" { opts.Split = "/v1/" diff --git a/openstack/objectstorage/v1/objects/urls.go b/openstack/objectstorage/v1/objects/urls.go index 4758a04f04..86f5823121 100644 --- a/openstack/objectstorage/v1/objects/urls.go +++ b/openstack/objectstorage/v1/objects/urls.go @@ -11,8 +11,8 @@ import ( // Names must not be URL-encoded in this case. // // See: https://docs.openstack.org/swift/latest/api/temporary_url_middleware.html#hmac-signature-for-temporary-urls -func tempURL(c *gophercloud.ServiceClient, container, object string) (string, error) { - return c.ServiceURL(container, object), nil +func tempURL(c *gophercloud.ServiceClient, container, object string) string { + return c.ServiceURL(container, object) } func listURL(c *gophercloud.ServiceClient, container string) (string, error) { diff --git a/pagination/testing/linked_test.go b/pagination/testing/linked_test.go index f73c3e14e2..83673f19b8 100644 --- a/pagination/testing/linked_test.go +++ b/pagination/testing/linked_test.go @@ -30,7 +30,7 @@ func ExtractLinkedInts(r pagination.Page) ([]int, error) { return s.Ints, err } -func createLinked(t *testing.T) pagination.Pager { +func createLinked() pagination.Pager { testhelper.SetupHTTP() testhelper.Mux.HandleFunc("/page1", func(w http.ResponseWriter, r *http.Request) { @@ -58,7 +58,7 @@ func createLinked(t *testing.T) pagination.Pager { } func TestEnumerateLinked(t *testing.T) { - pager := createLinked(t) + pager := createLinked() defer testhelper.TeardownHTTP() callCount := 0 @@ -100,7 +100,7 @@ func TestEnumerateLinked(t *testing.T) { } func TestAllPagesLinked(t *testing.T) { - pager := createLinked(t) + pager := createLinked() defer testhelper.TeardownHTTP() page, err := pager.AllPages(context.TODO()) diff --git a/testhelper/convenience.go b/testhelper/convenience.go index 8a6108e25c..166e60c5d1 100644 --- a/testhelper/convenience.go +++ b/testhelper/convenience.go @@ -268,7 +268,7 @@ func CheckDeepEquals(t *testing.T, expected, actual interface{}) { }) } -func isByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) bool { +func isByteArrayEquals(expectedBytes []byte, actualBytes []byte) bool { return bytes.Equal(expectedBytes, actualBytes) } @@ -276,7 +276,7 @@ func isByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) b func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) { t.Helper() - if !isByteArrayEquals(t, expectedBytes, actualBytes) { + if !isByteArrayEquals(expectedBytes, actualBytes) { logFatal(t, "The bytes differed.") } } @@ -285,7 +285,7 @@ func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byt func CheckByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) { t.Helper() - if !isByteArrayEquals(t, expectedBytes, actualBytes) { + if !isByteArrayEquals(expectedBytes, actualBytes) { logError(t, "The bytes differed.") } }