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

ci(golangci-lint): add unparam linter #6263

Closed
wants to merge 1 commit into from
Closed

ci(golangci-lint): add unparam linter #6263

wants to merge 1 commit into from

Conversation

acud
Copy link
Contributor

@acud acud commented Aug 15, 2024

Motivation

Adds the unparam linter.

Description

Test Plan

TODO

  • Explain motivation or link existing issue(s)
  • Test changes and document test plan
  • Update documentation as needed
  • Update changelog as needed

@acud acud force-pushed the add-unparam branch 2 times, most recently from 3ec0285 to d95fe07 Compare August 16, 2024 19:23
Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.1%. Comparing base (864aedb) to head (b7bb382).
Report is 5 commits behind head on develop.

Files Patch % Lines
api/grpcserver/v2alpha1/layer.go 80.0% 1 Missing ⚠️
node/node.go 50.0% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #6263   +/-   ##
=======================================
  Coverage     82.0%   82.1%           
=======================================
  Files          307     307           
  Lines        34105   34101    -4     
=======================================
+ Hits         27992   28007   +15     
+ Misses        4334    4315   -19     
  Partials      1779    1779           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acud acud marked this pull request as ready for review August 16, 2024 21:16
@@ -17,11 +17,12 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/mocks"
)

var nonce = types.VRFPostIndex(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about inlining types.VRFPostIndex(1) in gatx() instead of creating a global?

Copy link
Member

Choose a reason for hiding this comment

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

Also ideally it should not be the same value every time 😅

Comment on lines +22 to +25
// FIXME: pulled out to satisfy the linter but needs to be
// actually modified in tests to run different values.
epoch = types.EpochID(10)
round = types.RoundID(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Then perhaps add a //nolint with an explanation to the function definition instead?

Comment on lines -468 to +470
func (t *tester) estimateDrainGas(principal, vault, to, amount int, nonce core.Nonce) int {
const vaultVal = 20

func (t *tester) estimateDrainGas(principal, to, amount int, nonce core.Nonce) int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right way to fix it? Perhaps the tests should use different values?

Comment on lines +53 to +55
// FIXME: made to satisfy the linter but actually needs unit test
// changes to test different cases.
const iter1 = uint8(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using //nolint then?

@@ -753,7 +753,9 @@ func TestHandler(t *testing.T) {
})
}

func gatx(id types.ATXID, epoch types.EpochID, smesher types.NodeID, base, height uint64) types.ActivationTx {
const epoch = types.EpochID(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this linter if enabling it ends up using globals. The flow of information is broken now and the code is more difficult to follow.

Copy link
Member

Choose a reason for hiding this comment

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

Also I believe epoch should in at least one test be a different value from the others - or are all these tests seriously only interested in the very first epoch after genesis? I.e. the one where nothing happens except ATXs are published?

@@ -74,7 +73,6 @@ func launchPostSupervisor(
func launchPostSupervisorTLS(
Copy link
Member

Choose a reason for hiding this comment

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

This and launchPostSupervisor are basically identical, except that launchPostSupervisor doesn't yet use sql.InMemoryTest() and this function has the wrong name for the logger of the post manager.

I think launchPostSupervisorTLS can be removed and in the one place where it is called be replaced with launchPostSupervisor

@@ -17,11 +17,12 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/mocks"
)

var nonce = types.VRFPostIndex(1)
Copy link
Member

Choose a reason for hiding this comment

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

Also ideally it should not be the same value every time 😅

Comment on lines +22 to +23
hp, _ := cache.get(hash)
return hp
Copy link
Member

Choose a reason for hiding this comment

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

I feel like either here or where this helper is called an assertion for the boolean is missing (I believe it should always be true in the current tests).

@@ -1459,10 +1461,12 @@ func runTestCases(t *testing.T, tcs []templateTestCase, genTester func(t *testin
}
}

func testWallet(t *testing.T, defaultGasPrice int, template core.Address, genTester func(t *testing.T) *tester) {
const defaultGasPrice = 1
Copy link
Member

Choose a reason for hiding this comment

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

The defaultGasPrice was 20 before, why the change to 1? Also should this maybe be just different values for different tests?

func decodeVotes(evicted, blid types.LayerID, base *ballotInfo, exceptions types.Votes) (votes, types.LayerID, error) {
func decodeVotes(blid types.LayerID, base *ballotInfo, exceptions types.Votes) (votes, types.LayerID, error) {
Copy link
Member

Choose a reason for hiding this comment

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

That seems suspicious, are we sure that evicted is not needed and just wasn't forgotten when implementing decodeVotes?

Comment on lines +384 to +387
const (
start = 8
end = 20
)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like instead of making these constant the test above should just use different start and end layers for vesting. Wdyt?

Comment on lines +61 to 64
func unixPtr(sec int64) *time.Time {
t := time.Unix(sec, 0)
return &t
}
Copy link
Member

Choose a reason for hiding this comment

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

This function isn't needed in my opinion. epochStart can just be a value instead of a pointer and instead of checking it for nil one can call epochStart.IsZero() on it to see if it was set or not.

Wdyt?

@@ -182,8 +186,10 @@ type setup struct {
proposals []types.ProposalID
}

func (s *setup) thresh(v uint16) *setup {
s.threshold = v
const threshold = 10
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, probably // nolint is the way to go and fix it at some later point.

@@ -928,7 +928,9 @@ func TestHandler(t *testing.T) {
})
}

func gatx(id types.ATXID, epoch types.EpochID, smesher types.NodeID, base, height uint64) types.ActivationTx {
const epoch = types.EpochID(1)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, epoch 1 is different from all other epochs, we shouldn't only test for that specific. We should have at least a single test where epoch is a different value.

func (t *toutput) iter(i uint8) *toutput {
// FIXME: made to satisfy the linter but actually needs unit test
// changes to test different cases.
const iter1 = uint8(1)
Copy link
Member

Choose a reason for hiding this comment

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

Just like in the other places, I believe we should have variable values for this in different tests and if we don't change it within this PR, then // nolint for now.

@@ -182,8 +186,10 @@ type setup struct {
proposals []types.ProposalID
}

func (s *setup) thresh(v uint16) *setup {
s.threshold = v
const threshold = 10
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

@@ -145,9 +147,10 @@ func expectMeshHash(hash types.Hash32) expectOpt {
}
}

const epochExpectCounter = types.EpochID(3)
Copy link
Member

Choose a reason for hiding this comment

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

This should probably always be epoch+1 and epoch should again vary between tests (or // nolint)

@acud
Copy link
Contributor Author

acud commented Aug 19, 2024

Thanks for the review guys, but the intent here was to enable the linter, however, I think that addressing all this will make this PR huge and unreasonable to review. We should probably fix the underlying issues and then enable the linter. Thanks

@acud acud closed this Aug 19, 2024
@acud acud deleted the add-unparam branch August 19, 2024 16:58
@@ -83,8 +84,10 @@ func geligibilities(js ...uint32) (rst []types.VotingEligibility) {
return rst
}

const j = uint32(1)
Copy link
Member

Choose a reason for hiding this comment

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

This also feels like it should vary between tests

@@ -17,11 +17,13 @@ import (
"github.com/spacemeshos/go-spacemesh/sql/transactions"
)

const amount = uint64(191)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should vary between tests.

@@ -125,12 +127,14 @@ type bopt struct {
opts []ballotOpt
}

func (b *bopt) beacon(value string) *bopt {
const beaconVal = "a"
Copy link
Member

Choose a reason for hiding this comment

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

This can probably be inlined

@@ -77,9 +77,11 @@ func (s *smesher) rawatx(id types.ATXID, publish types.EpochID, opts ...*aopt) *
return val
}

const publish = 1
Copy link
Member

Choose a reason for hiding this comment

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

As stated before, epoch 1 is special different from all other epochs, we should have at least one test were we have a different publish epoch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants