From 27f2b62be9b4ec1b5cc92656a49da1cf1ca28d9f Mon Sep 17 00:00:00 2001
From: Fabian Seidl <fabian.b.seidl@stud.h-da.de>
Date: Mon, 1 Aug 2022 14:38:01 +0200
Subject: [PATCH] some code simplification, enabled type assertion in errcheck
 again

---
 .golangci.yml                                           | 4 +++-
 controller/nucleus/deviceWatcher.go                     | 2 +-
 controller/nucleus/errors/errors.go                     | 8 ++++----
 controller/nucleus/gnmi_transport_test.go               | 1 +
 controller/topology/nodes/nodeStore.go                  | 2 +-
 controller/topology/ports/portStore.go                  | 2 +-
 controller/topology/routing-tables/routingTableStore.go | 2 +-
 controller/topology/topologyStore.go                    | 2 +-
 csbi/repository.go                                      | 2 +-
 9 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index f0965a4cb..d1d361154 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -32,6 +32,8 @@ issues:
 
 linters:
     # enable the specific needed linters
+    # see here for full list: https://golangci-lint.run/usage/linters/
+    # linters to consider: gosimple,
     disable-all: true
     enable:
         - gofmt
@@ -56,4 +58,4 @@ linters-settings:
         # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
         # Such cases aren't reported by default.
         # Default: false
-        check-type-assertions: false
+        check-type-assertions: true
diff --git a/controller/nucleus/deviceWatcher.go b/controller/nucleus/deviceWatcher.go
index de7f135af..1f02d5c21 100644
--- a/controller/nucleus/deviceWatcher.go
+++ b/controller/nucleus/deviceWatcher.go
@@ -124,7 +124,7 @@ func (d *DeviceWatcher) handleSubscribeResponse(resp *gpb.SubscribeResponse, sub
 			PndID:      subscriptionInfo.PndID,
 			DeviceID:   subscriptionInfo.DeviceID,
 			DeviceName: subscriptionInfo.DeviceName,
-			Err:        fmt.Sprintf("SubscribeResponse_Error"),
+			Err:        fmt.Sprint("SubscribeResponse_Error"),
 		})
 	case *gpb.SubscribeResponse_SyncResponse:
 		if !resp.SyncResponse {
diff --git a/controller/nucleus/errors/errors.go b/controller/nucleus/errors/errors.go
index 254cb1653..19f2b7055 100644
--- a/controller/nucleus/errors/errors.go
+++ b/controller/nucleus/errors/errors.go
@@ -12,7 +12,7 @@ type ErrNilClient struct {
 }
 
 func (e *ErrNilClient) Error() string {
-	return fmt.Sprintf("client cannot be nil")
+	return fmt.Sprint("client cannot be nil")
 }
 
 // ErrNil implements the Error interface and is called if a struct is nil.
@@ -20,7 +20,7 @@ type ErrNil struct {
 }
 
 func (e *ErrNil) Error() string {
-	return fmt.Sprintf("struct cannot be nil")
+	return fmt.Sprint("struct cannot be nil")
 }
 
 // ErrAlreadyExists implements the Error interface and is called if a specific ID
@@ -39,7 +39,7 @@ type ErrInvalidUUID struct {
 }
 
 func (e *ErrInvalidUUID) Error() string {
-	return fmt.Sprintf("UUID not valid")
+	return fmt.Sprint("UUID not valid")
 }
 
 // ErrInvalidTypeAssertion implements the Error interface and is called if the
@@ -79,7 +79,7 @@ func (e ErrPathNotFound) Error() string {
 type ErrNotYetImplemented struct{}
 
 func (e ErrNotYetImplemented) Error() string {
-	return fmt.Sprintf("function not yet implemented")
+	return fmt.Sprint("function not yet implemented")
 }
 
 // ErrInvalidParameters implements the Error interface and is called if the wrong
diff --git a/controller/nucleus/gnmi_transport_test.go b/controller/nucleus/gnmi_transport_test.go
index deb6742db..87a1909ae 100644
--- a/controller/nucleus/gnmi_transport_test.go
+++ b/controller/nucleus/gnmi_transport_test.go
@@ -439,6 +439,7 @@ func TestGnmi_Type(t *testing.T) {
 	}
 }
 
+//nolint:errcheck
 func TestGnmi_getWithRequest(t *testing.T) {
 	transport := mockTransport()
 	reqFullNode := gnmiMessages["../test/proto/req-full-node"].(*gpb.GetRequest)
diff --git a/controller/topology/nodes/nodeStore.go b/controller/topology/nodes/nodeStore.go
index 0c0093b20..90891452e 100644
--- a/controller/topology/nodes/nodeStore.go
+++ b/controller/topology/nodes/nodeStore.go
@@ -30,7 +30,7 @@ type DatabaseNodeStore struct {
 // NewDatabaseNodeStore returns a NodeStore
 func NewDatabaseNodeStore() Store {
 	return &DatabaseNodeStore{
-		storeName: fmt.Sprintf("node-store.json"),
+		storeName: fmt.Sprint("node-store.json"),
 	}
 }
 
diff --git a/controller/topology/ports/portStore.go b/controller/topology/ports/portStore.go
index e09bbd8fb..45907c054 100644
--- a/controller/topology/ports/portStore.go
+++ b/controller/topology/ports/portStore.go
@@ -31,7 +31,7 @@ type DatabasePortStore struct {
 // NewDatabasePortStore returns a PortStore
 func NewDatabasePortStore() Store {
 	return &DatabasePortStore{
-		storeName: fmt.Sprintf("port-store.json"),
+		storeName: fmt.Sprint("port-store.json"),
 	}
 }
 
diff --git a/controller/topology/routing-tables/routingTableStore.go b/controller/topology/routing-tables/routingTableStore.go
index a0afbf140..72aa625c6 100644
--- a/controller/topology/routing-tables/routingTableStore.go
+++ b/controller/topology/routing-tables/routingTableStore.go
@@ -30,7 +30,7 @@ type DatabaseRoutingTableStore struct {
 // NewDatabaseRoutingTableStore returns a RoutingTableStore
 func NewDatabaseRoutingTableStore() Store {
 	return &DatabaseRoutingTableStore{
-		storeName: fmt.Sprintf("routing-table-store.json"),
+		storeName: fmt.Sprint("routing-table-store.json"),
 	}
 }
 
diff --git a/controller/topology/topologyStore.go b/controller/topology/topologyStore.go
index 9b50376c1..ed9318e03 100644
--- a/controller/topology/topologyStore.go
+++ b/controller/topology/topologyStore.go
@@ -31,7 +31,7 @@ type DatabaseTopologyStore struct {
 // NewDatabaseTopologyStore returns a TopologyStore
 func NewDatabaseTopologyStore() Store {
 	return &DatabaseTopologyStore{
-		storeName: fmt.Sprintf("topology-store.json"),
+		storeName: fmt.Sprint("topology-store.json"),
 	}
 }
 
diff --git a/csbi/repository.go b/csbi/repository.go
index 3a96d5c6d..92a4ce9c1 100644
--- a/csbi/repository.go
+++ b/csbi/repository.go
@@ -114,7 +114,7 @@ func (osfs *filesystem) Stat(name string) (fs.FileInfo, error) {
 func (osfs *filesystem) Glob(pattern string) (paths []string, err error) {
 	defer func() {
 		if e := recover(); e != nil {
-			err = e.(error)
+			err = e.(error) //nolint:errcheck
 			paths = nil
 		}
 	}()
-- 
GitLab