-
Notifications
You must be signed in to change notification settings - Fork 212
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
Conversation
3ec0285
to
d95fe07
Compare
Codecov ReportAttention: Patch coverage is
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. |
@@ -17,11 +17,12 @@ import ( | |||
"github.com/spacemeshos/go-spacemesh/sql/mocks" | |||
) | |||
|
|||
var nonce = types.VRFPostIndex(1) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😅
// 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) |
There was a problem hiding this comment.
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?
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 { |
There was a problem hiding this comment.
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?
// FIXME: made to satisfy the linter but actually needs unit test | ||
// changes to test different cases. | ||
const iter1 = uint8(1) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 😅
hp, _ := cache.get(hash) | ||
return hp |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
const ( | ||
start = 8 | ||
end = 20 | ||
) |
There was a problem hiding this comment.
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?
func unixPtr(sec int64) *time.Time { | ||
t := time.Unix(sec, 0) | ||
return &t | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
)
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 |
@@ -83,8 +84,10 @@ func geligibilities(js ...uint32) (rst []types.VotingEligibility) { | |||
return rst | |||
} | |||
|
|||
const j = uint32(1) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Motivation
Adds the
unparam
linter.Description
Test Plan
TODO