-
Notifications
You must be signed in to change notification settings - Fork 61
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
Use the nested if's linter to reduce complexity globally #1629
Conversation
@pysel is attempting to deploy a commit to the quicksilver Team on Vercel. A member of the Team first needs to authorize it. |
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes introduce the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant Keeper
participant Zone
User->>Keeper: Call HandleAcknowledgement
Keeper->>Zone: SetValidatorForZone
Zone->>Keeper: Validator Set
Keeper->>User: Acknowledgement Handled
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
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.
Thanks @pysel for contributing! Could you fix the lint errors after adding the gocyclo lint? It seems there's quite lot of work to be done, would be very nice if we can actually reduce the complexity globally.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1629 +/- ##
=======================================
Coverage 63.60% 63.60%
=======================================
Files 195 195
Lines 13773 13773
=======================================
Hits 8760 8760
Misses 4156 4156
Partials 857 857
Flags with carried forward coverage won't be shown. Click here to find out more.
|
hey @tropicaldog . I added nolints to problematic places. I do not have much context on problematic functions, so I would probably not try to refactor them, since I might introduce unexpected bugs by doing that CI should pass now though |
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.
Actionable comments posted: 3
Outside diff range and nitpick comments (2)
x/interchainstaking/keeper/ibc_packet_handlers.go (2)
Line range hint
110-110
: Refactor error handling for better clarity.Consider refactoring the error handling in the case for
/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward
to separate the logic of error checking and response handling for better clarity and maintainability.
Line range hint
130-130
: Standardize error messages for consistency.The error messages in the case for
/cosmos.staking.v1beta1.MsgRedeemTokensForShares
vary significantly. Standardizing these messages would improve the readability and maintainability of the code.
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- cmd/quicksilverd/genaccounts.go (1 hunks)
- x/interchainstaking/keeper/callbacks_test.go (1 hunks)
- x/interchainstaking/keeper/ibc_packet_handlers.go (1 hunks)
- x/interchainstaking/keeper/keeper.go (1 hunks)
- x/interchainstaking/keeper/proposal_handler.go (1 hunks)
Files skipped from review due to trivial changes (3)
- cmd/quicksilverd/genaccounts.go
- x/interchainstaking/keeper/callbacks_test.go
- x/interchainstaking/keeper/proposal_handler.go
Additional comments not posted (1)
x/interchainstaking/keeper/ibc_packet_handlers.go (1)
Line range hint
150-150
: Verify conditions before processing tokenization.Ensure that all preconditions are verified before processing the tokenization of shares in the case for
/cosmos.staking.v1beta1.MsgTokenizeShares
. This may include checking the validity of the input data and the state of related entities.
@@ -324,6 +324,7 @@ func (k *Keeper) SetValidatorsForZone(ctx sdk.Context, data []byte, icqQuery icq | |||
return nil | |||
} | |||
|
|||
// nolint:gocyclo |
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 use of //nolint:gocyclo
is justified given the complexity of the function. However, consider refactoring to improve maintainability.
Tip
Codebase Verification
The SetValidatorForZone
function in x/interchainstaking/keeper/keeper.go
includes error handling and checks for nil data. Specifically, it logs an error and returns nil if the data
parameter is nil, and it handles various error conditions throughout its logic.
However, the test cases in x/interchainstaking/keeper/keeper_test.go
and x/interchainstaking/client/cli/cli_test.go
do not appear to cover all error paths explicitly. The tests reference SetValidatorForZone
, but they do not seem to verify the function's behavior in the presence of nil data or other specific error conditions.
-
Implementation of
SetValidatorForZone
:- Handles nil
data
by logging an error and returning nil. - Handles errors from
UnmarshalValidator
,ValAddressFromBech32
, and other operations by logging and returning the errors.
- Handles nil
-
Test Coverage:
- Tests in
keeper_test.go
andcli_test.go
referenceSetValidatorForZone
but do not explicitly test all error paths.
- Tests in
To ensure comprehensive test coverage, additional unit tests should be added to explicitly verify the function's behavior when data
is nil and when other errors occur.
- Files to update:
x/interchainstaking/keeper/keeper_test.go
x/interchainstaking/client/cli/cli_test.go
Analysis chain
Verify the correct handling of nil data and error propagation.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify that all error paths in `SetValidatorForZone` are covered by unit tests.
# Test: Search for unit tests covering `SetValidatorForZone`. Expect: Tests covering all error paths.
rg --type go $'func Test.*SetValidatorForZone.*'
Length of output: 49
Script:
#!/bin/bash
# Locate the implementation of the `SetValidatorForZone` function in the codebase.
ast-grep --lang go --pattern 'func SetValidatorForZone($_, $_) $_'
# Search for any related tests that might indirectly cover the `SetValidatorForZone` function.
rg --type go 'SetValidatorForZone'
Length of output: 847
Script:
#!/bin/bash
# Extract the implementation of the `SetValidatorForZone` function.
ast-grep --lang go --pattern 'func (k *Keeper) SetValidatorForZone(ctx sdk.Context, zone *types.Zone, data []byte) error {
$$$
}' x/interchainstaking/keeper/keeper.go
# Extract the test cases from `x/interchainstaking/keeper/keeper_test.go` and `x/interchainstaking/client/cli/cli_test.go` that reference `SetValidatorForZone`.
rg --type go --context 10 'SetValidatorForZone' x/interchainstaking/keeper/keeper_test.go x/interchainstaking/client/cli/cli_test.go
Length of output: 16592
@@ -62,6 +62,7 @@ func DeserializeCosmosTxTyped(cdc codec.BinaryCodec, data []byte) ([]TypedMsg, e | |||
return msgs, nil | |||
} | |||
|
|||
//nolint:gocyclo |
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.
Ensure proper documentation for HandleAcknowledgement
.
The function HandleAcknowledgement
is complex and handles many different message types. It would benefit from detailed documentation explaining each case and the overall flow.
Yeah I guess this PR should be merged after the lint issue is fixed, wdyt @faddat @joe-bowman? |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you! |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you! |
1. Summary
Fixes #1609
Enables gocyclo linter