Repository: Shopify/sarama
Pull request #1337 (2019-04-01 20:42:28)

Address a few staticcheck suggestions
Suggestions by the `staticcheck` tool (https://staticcheck.io/).


Patch:
diff --git a/admin.go b/admin.go
index 372048b..81bdfb5 100644
--- a/admin.go
+++ b/admin.go
@@ -20,7 +20,7 @@ type ClusterAdmin interface {
 	// List the topics available in the cluster with the default options.
 	ListTopics() (map[string]TopicDetail, error)
 
-	// Describe some topics in the cluster.
+	// Describe some topics in the cluster
 	DescribeTopics(topics []string) (metadata []*TopicMetadata, err error)
 
 	// Delete a topic. It may take several seconds after the DeleteTopic to returns success
@@ -78,13 +78,13 @@ type ClusterAdmin interface {
 	// List the consumer groups available in the cluster.
 	ListConsumerGroups() (map[string]string, error)
 
-	// Describe the given consumer groups.
+	// Describe the given consumer group
 	DescribeConsumerGroups(groups []string) ([]*GroupDescription, error)
 
 	// List the consumer group offsets available in the cluster.
 	ListConsumerGroupOffsets(group string, topicPartitions map[string][]int32) (*OffsetFetchResponse, error)
 
-	// Get information about the nodes in the cluster.
+	// Get information about the nodes in the cluster
 	DescribeCluster() (brokers []*Broker, controllerID int32, err error)
 
 	// Close shuts down the admin and closes underlying client.
@@ -131,7 +131,7 @@ func (ca *clusterAdmin) CreateTopic(topic string, detail *TopicDetail, validateO
 	}
 
 	if detail == nil {
-		return errors.New("You must specify topic details")
+		return errors.New("you must specify topic details")
 	}
 
 	topicDetails := make(map[string]*TopicDetail)
diff --git a/broker.go b/broker.go
index 12ee4f0..739f001 100644
--- a/broker.go
+++ b/broker.go
@@ -1097,7 +1097,7 @@ func buildClientInitialResponse(token *AccessToken) ([]byte, error) {
 
 	if token.Extensions != nil && len(token.Extensions) > 0 {
 		if _, ok := token.Extensions[SASLExtKeyAuth]; ok {
-			return []byte{}, fmt.Errorf("The extension `%s` is invalid", SASLExtKeyAuth)
+			return []byte{}, fmt.Errorf("the extension `%s` is invalid", SASLExtKeyAuth)
 		}
 		ext = "\x01" + mapToString(token.Extensions, "=", "\x01")
 	}
diff --git a/client.go b/client.go
index 10a948b..9422f46 100644
--- a/client.go
+++ b/client.go
@@ -793,7 +793,7 @@ func (client *client) updateMetadata(data *MetadataResponse, allKnownMetaData bo
 
 		switch topic.Err {
 		case ErrNoError:
-			break
+			// no-op
 		case ErrInvalidTopic, ErrTopicAuthorizationFailed: // don't retry, don't store partial results
 			err = topic.Err
 			continue
@@ -803,7 +803,6 @@ func (client *client) updateMetadata(data *MetadataResponse, allKnownMetaData bo
 			continue
 		case ErrLeaderNotAvailable: // retry, but store partial partition results
 			retry = true
-			break
 		default: // don't retry, don't store partial results
 			Logger.Printf("Unexpected topic-level metadata error: %s", topic.Err)
 			err = topic.Err
diff --git a/config.go b/config.go
index 6fa8bb9..a35f664 100644
--- a/config.go
+++ b/config.go
@@ -419,10 +419,10 @@ func NewConfig() *Config {
 // ConfigurationError if the specified values don't make sense.
 func (c *Config) Validate() error {
 	// some configuration values should be warned on but not fail completely, do those first
-	if c.Net.TLS.Enable == false && c.Net.TLS.Config != nil {
+	if !c.Net.TLS.Enable && c.Net.TLS.Config != nil {
 		Logger.Println("Net.TLS is disabled but a non-nil configuration was provided.")
 	}
-	if c.Net.SASL.Enable == false {
+	if !c.Net.SASL.Enable {
 		if c.Net.SASL.User != "" {
 			Logger.Println("Net.SASL is disabled but a non-empty username was provided.")
 		}
diff --git a/consumer.go b/consumer.go
index 27a6424..8ddecc4 100644
--- a/consumer.go
+++ b/consumer.go
@@ -746,7 +746,7 @@ func (bc *brokerConsumer) updateSubscriptions(newSubscriptions []*partitionConsu
 			close(child.trigger)
 			delete(bc.subscriptions, child)
 		default:
-			break
+			// no-op
 		}
 	}
 }
@@ -759,7 +759,7 @@ func (bc *brokerConsumer) handleResponses() {
 
 		switch result {
 		case nil:
-			break
+			// no-op
 		case errTimedOut:
 			Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because consuming was taking too long\n",
 				bc.broker.ID(), child.topic, child.partition)
diff --git a/mockresponses.go b/mockresponses.go
index 54ddb1a..231f35b 100644
--- a/mockresponses.go
+++ b/mockresponses.go
@@ -626,7 +626,7 @@ func (mr *MockCreateTopicsResponse) For(reqBody versionedDecoder) encoder {
 	}
 	res.TopicErrors = make(map[string]*TopicError)
 
-	for topic, _ := range req.TopicDetails {
+	for topic := range req.TopicDetails {
 		if res.Version >= 1 && strings.HasPrefix(topic, "_") {
 			msg := "insufficient permissions to create topic with reserved prefix"
 			res.TopicErrors[topic] = &TopicError{
@@ -672,7 +672,7 @@ func (mr *MockCreatePartitionsResponse) For(reqBody versionedDecoder) encoder {
 	res := &CreatePartitionsResponse{}
 	res.TopicPartitionErrors = make(map[string]*TopicPartitionError)
 
-	for topic, _ := range req.TopicPartitions {
+	for topic := range req.TopicPartitions {
 		if strings.HasPrefix(topic, "_") {
 			msg := "insufficient permissions to create partition on topic with reserved prefix"
 			res.TopicPartitionErrors[topic] = &TopicPartitionError{
@@ -701,7 +701,7 @@ func (mr *MockDeleteRecordsResponse) For(reqBody versionedDecoder) encoder {
 
 	for topic, deleteRecordRequestTopic := range req.Topics {
 		partitions := make(map[int32]*DeleteRecordsResponsePartition)
-		for partition, _ := range deleteRecordRequestTopic.PartitionOffsets {
+		for partition := range deleteRecordRequestTopic.PartitionOffsets {
 			partitions[partition] = &DeleteRecordsResponsePartition{Err: ErrNoError}
 		}
 		res.Topics[topic] = &DeleteRecordsResponseTopic{Partitions: partitions}
diff --git a/offset_commit_request.go b/offset_commit_request.go
index 1ec583e..5732ed9 100644
--- a/offset_commit_request.go
+++ b/offset_commit_request.go
@@ -200,11 +200,11 @@ func (r *OffsetCommitRequest) AddBlock(topic string, partitionID int32, offset i
 func (r *OffsetCommitRequest) Offset(topic string, partitionID int32) (int64, string, error) {
 	partitions := r.blocks[topic]
 	if partitions == nil {
-		return 0, "", errors.New("No such offset")
+		return 0, "", errors.New("no such offset")
 	}
 	block := partitions[partitionID]
 	if block == nil {
-		return 0, "", errors.New("No such offset")
+		return 0, "", errors.New("no such offset")
 	}
 	return block.offset, block.metadata, nil
 }
diff --git a/offset_manager.go b/offset_manager.go
index 8e451a2..923972f 100644
--- a/offset_manager.go
+++ b/offset_manager.go
@@ -333,7 +333,6 @@ func (om *offsetManager) handleResponse(broker *Broker, req *OffsetCommitRequest
 				pom.handleError(err)
 			case ErrOffsetsLoadInProgress:
 				// nothing wrong but we didn't commit, we'll get it next time round
-				break
 			case ErrUnknownTopicOrPartition:
 				// let the user know *and* try redispatching - if topic-auto-create is
 				// enabled, redispatching should trigger a metadata req and create the
diff --git a/produce_set.go b/produce_set.go
index 4b42d9c..bba0f7e 100644
--- a/produce_set.go
+++ b/produce_set.go
@@ -81,7 +81,7 @@ func (ps *produceSet) add(msg *ProducerMessage) error {
 
 	if ps.parent.conf.Version.IsAtLeast(V0_11_0_0) {
 		if ps.parent.conf.Producer.Idempotent && msg.sequenceNumber < set.recordsToSend.RecordBatch.FirstSequence {
-			return errors.New("Assertion failed: Message out of sequence added to a batch")
+			return errors.New("assertion failed: message out of sequence added to a batch")
 		}
 		// We are being conservative here to avoid having to prep encode the record
 		size += maximumRecordOverhead


Test patch:
diff --git a/admin_test.go b/admin_test.go
index 2233263..7fd008f 100644
--- a/admin_test.go
+++ b/admin_test.go
@@ -97,7 +97,7 @@ func TestClusterAdminCreateTopicWithInvalidTopicDetail(t *testing.T) {
 	}
 
 	err = admin.CreateTopic("my_topic", nil, false)
-	if err.Error() != "You must specify topic details" {
+	if err.Error() != "you must specify topic details" {
 		t.Fatal(err)
 	}
 	err = admin.Close()