Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove redundant nil check #3089

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

knbr13
Copy link
Contributor

@knbr13 knbr13 commented Jan 31, 2025

mocks/async_producer.go remove unnecessay nil check.

var slice []byte
if slice == nil || len(slice) == 0 {}
// is the same as
if len(slice) == 0 {}

because len(slice) where slice == nil is always equal to 0,

staticcheck will highlight this optimization with the following message:

mocks/async_producer.go:77:7: should omit nil check; len() for []*github.com/IBM/sarama/mocks.producerExpectation is defined as zero (S1009)

for reference: staticcheck S1009

Copy link
Contributor

@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.

Yep. 👍

@dnwe
Copy link
Collaborator

dnwe commented Feb 1, 2025

Interesting that we’re not getting this flagged by staticcheck in our golangci-lint runs as we definitely have sc enabled here

@puellanivis
Copy link
Contributor

Interesting that we’re not getting this flagged by staticcheck in our golangci-lint runs as we definitely have sc enabled here

disable-all: true

  disable-all: true

This might be related?

@dnwe
Copy link
Collaborator

dnwe commented Feb 2, 2025

  disable-all: true

This might be related?

That’s just the config equivalent of the cli flag to disable all the default linters and only enable explicitly defined ones

@dnwe
Copy link
Collaborator

dnwe commented Feb 2, 2025

Very strange, run via golangci-lint we get no results for staticcheck even if we disable all config and default excludes:

% golangci-lint-1.62.2 run --no-config --disable-all --enable=staticcheck --exclude-use-default=false .

But standalone staticcheck flags a few different things including S1009:

% staticcheck ./...
balance_strategy.go:993:30: func (*partitionMovements).isLinked is unused (U1000)
balance_strategy.go:1028:30: func (*partitionMovements).in is unused (U1000)
balance_strategy.go:1043:30: func (*partitionMovements).hasCycles is unused (U1000)
balance_strategy.go:1075:30: func (*partitionMovements).isSticky is unused (U1000)
balance_strategy.go:1093:6: func indexOfSubList is unused (U1000)
metrics_helpers_test.go:120:6: func minMaxHistogramValidator is unused (U1000)
mocks/async_producer.go:77:7: should omit nil check; len() for []*github.com/IBM/sarama/mocks.producerExpectation is defined as zero (S1009)
mocks/mocks.go:55:41: error strings should not be capitalized (ST1005)
mocks/mocks.go:56:41: error strings should not be capitalized (ST1005)

@knbr13
Copy link
Contributor Author

knbr13 commented Feb 2, 2025

the staticcheck linter used by golangci-lint isn't the same as the standalone staticcheck tool.
according to golangci-lint's documentation, the author of staticcheck does not approve its use as a library inside golangci-lint.
this could explain why some checks, like S1009, are flagged when running staticcheck directly but not via golangci-lint.

golangci-lint-docs-staticcheck

for reference: https://golangci-lint.run/usage/linters/#staticcheck

Copy link
Collaborator

@dnwe dnwe left a comment

Choose a reason for hiding this comment

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

Lgtm

@dnwe dnwe merged commit 685ed7e into IBM:main Feb 3, 2025
16 checks passed
@dnwe dnwe added the fix label Feb 3, 2025
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