Skip to content

chore: apply modernize fixes from gopls#3297

Merged
dnwe merged 7 commits intomainfrom
dnwe/sarama-modernize
Sep 18, 2025
Merged

chore: apply modernize fixes from gopls#3297
dnwe merged 7 commits intomainfrom
dnwe/sarama-modernize

Conversation

@dnwe
Copy link
Copy Markdown
Collaborator

@dnwe dnwe commented Sep 18, 2025

Apply a selection of the gopls modernize fixes category-by-category:

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -category=$CAT ./...

@dnwe dnwe added the chore label Sep 18, 2025
@dnwe dnwe merged commit dedff7a into main Sep 18, 2025
17 checks passed
@dnwe dnwe deleted the dnwe/sarama-modernize branch September 18, 2025 09:26
Copy link
Copy Markdown
Collaborator

@puellanivis puellanivis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it’s already merged, but spotted a few further polishings.

for group, typ := range response.Groups {
groups[group] = typ
}
maps.Copy(groups, response.Groups)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we’re also making the map on line 1034, we can replace this with groups := maps.Clone(response.Groups)

for k, v := range currentPartitionConsumer {
preBalancePartitionConsumers[k] = v
}
maps.Copy(preBalancePartitionConsumers, currentPartitionConsumer)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a good candidate for maps.Clone

for k, v := range preBalancePartitionConsumers {
currentPartitionConsumer[k] = v
}
maps.Copy(currentPartitionConsumer, preBalancePartitionConsumers)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps.Clone.

}
}
return false
return slices.Contains(assignments, topic)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to replace the actual function calls to this unexported function to slices.Contains itself?

Comment on lines +2205 to 2206
found := slices.Contains(consumers[memberID].Topics, assignedTopic)
if !found {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to go through a temporary local variable anymore, we could just do the slices.Contains directly in the if condition.

for k, v := range handlerMap {
fnMap[k] = v
}
maps.Copy(fnMap, handlerMap)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps.Clone.

for k, v := range handlerMap {
fnMap[k] = v
}
maps.Copy(fnMap, handlerMap)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps.Clone.

Comment on lines +106 to +107
arrHdrs := strings.SplitSeq(*headers, ",")
for h := range arrHdrs {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pass this through a temporary local variable.

Comment on lines +1673 to 1675
resp := fmt.Appendf(nil, "n,,\x01auth=Bearer %s%s\x01\x01", token.Token, ext)

return resp, nil
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn’t seem to be necessary to pass through a temporary local variable, but the composed return might look more odd.

hindessm added a commit to hindessm/sarama that referenced this pull request Sep 22, 2025
These are the uncontentious changes mentioned after the merge
of the earlier modernize PR. See:

  IBM#3297 (review)

Co-authored-by: Cassondra Foesch <[email protected]>
Signed-off-by: beanz <[email protected]>
hindessm added a commit to hindessm/sarama that referenced this pull request Sep 22, 2025
These are the uncontentious changes mentioned after the merge
of the earlier modernize PR. See:

  IBM#3297 (review)

Co-authored-by: Cassondra Foesch <[email protected]>
Signed-off-by: beanz <[email protected]>
hindessm added a commit that referenced this pull request Sep 23, 2025
These are the uncontentious changes mentioned after the merge
of the earlier modernize PR. See:

  #3297 (review)

Co-authored-by: Cassondra Foesch <[email protected]>
Signed-off-by: beanz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants