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

chore: use the nested if's linter to reduce complexity globally #1158

Closed
wants to merge 23 commits into from

Conversation

faddat
Copy link
Contributor

@faddat faddat commented Feb 16, 2024

1. Summary

Enable some new linters I learned while fixing CometBFT tests

notes

  • When main is merged into this PR, issues crop up fast. Can someone try merging main here? I haven't figured out what the issue is yet.
  • we will wait until after the next release is out to merge this PR

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

4. How to test/use

5. Checklist

  • Does the Readme need to be updated?

6. Limitations (optional)

7. Future Work (optional)

Summary by CodeRabbit

  • Refactor
    • Improved type safety by changing types from interface{} to any in various components.
    • Refactored airdrop functionality for enhanced clarity and logic.
    • Organized claims manager code for better clarity.
    • Updated interchain functionality with improved logic and clarity.
    • Simplified method signatures in several components for better readability.
    • Enhanced message dispatching in CustomMessenger for TokenFactoryMsg with clearer logic.
    • Improved delegation logic in interchain staking with new functions and refined error handling.
  • Chores
    • Updated linter configurations for better code quality checks.

@faddat faddat requested a review from joe-bowman as a code owner February 16, 2024 23:29
Copy link

vercel bot commented Feb 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ❌ Failed (Inspect) Apr 8, 2024 7:40am

Copy link
Contributor

coderabbitai bot commented Feb 16, 2024

Important

Auto Review Skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The updates encompass a broad refinement of codebase practices, focusing on enhancing type safety, clarity, and maintainability. Key changes include the integration and removal of specific linters, transitioning from interface{} to any for type declarations, and methodological improvements across various functionalities, notably in airdrop, claims management, and interchain operations. These modifications aim to streamline code readability and efficiency, reflecting a meticulous effort to adhere to modern Go practices.

Changes

Files Summary
.golangci.yml Added maintidx, nestif, testifylint; removed specific rules from linter settings.
app/.../test_helpers.go, app/.../tps_counter_test.go, cmd/..., server/..., test/..., third-party-chains/..., utils/sort.go, wasmbinding/..., x/... Updated types from interface{} to any for enhanced type safety and clarity.
x/airdrop/..., x/claimsmanager/... Refactored airdrop and claims manager functionalities for improved logic and clarity.
x/interchainquery/..., x/interchainstaking/... Enhanced interchain functionalities with updated logic and clarity.
x/lsmtypes/msg.go, x/mint/types/params.go Simplified method signatures for better readability and maintenance.
wasmbinding/message_plugin.go Refactored DispatchMsg method for clearer and more maintainable logic.

"In the realm of code, where logic intertwines,
A rabbit hopped through, refining lines.
From any to interface{}, across the vast files,
It leaped and it tweaked, with the softest of smiles.
🐇 With each hop and change, the codebase did glow,
A testament to progress, in the digital flow."

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9336197 and f086a2b.
Files selected for processing (1)
  • .golangci.yml (3 hunks)
Additional comments: 1
.golangci.yml (1)
  • 21-21: The addition of the maintidx linter is a positive change aimed at enhancing code maintainability checks. This aligns with the PR's objective to improve code quality and maintainability. Ensure that the project's CI pipeline is configured to handle the potential increase in analysis time due to the addition of this linter.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

Attention: Patch coverage is 73.10924% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 63.40%. Comparing base (fcd7917) to head (3e91bb5).
Report is 67 commits behind head on main.

❗ Current head 3e91bb5 differs from pull request most recent head 690bd5c. Consider uploading reports for the commit 690bd5c to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1158      +/-   ##
==========================================
- Coverage   63.60%   63.40%   -0.21%     
==========================================
  Files         171      171              
  Lines       11652    11159     -493     
==========================================
- Hits         7411     7075     -336     
+ Misses       3497     3373     -124     
+ Partials      744      711      -33     
Flag Coverage Δ
unittests 63.40% <73.10%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
cmd/quicksilverd/root.go 56.35% <100.00%> (ø)
x/airdrop/types/airdrop.go 100.00% <100.00%> (ø)
x/claimsmanager/keeper/abci.go 100.00% <100.00%> (ø)
x/claimsmanager/keeper/hooks.go 78.57% <100.00%> (ø)
x/interchainquery/keeper/keeper.go 75.00% <100.00%> (ø)
x/interchainquery/keeper/queries.go 95.74% <ø> (ø)
x/interchainstaking/keeper/callbacks.go 64.52% <100.00%> (+0.77%) ⬆️
x/interchainstaking/types/delegation.go 76.57% <100.00%> (-1.01%) ⬇️
x/mint/types/params.go 50.47% <100.00%> (ø)
x/participationrewards/keeper/callbacks.go 53.49% <100.00%> (ø)
... and 13 more

... and 23 files with indirect coverage changes

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f086a2b and 421d82d.
Files selected for processing (1)
  • .golangci.yml (3 hunks)
Additional comments: 2
.golangci.yml (2)
  • 23-23: The addition of the nestif linter is a positive change for enhancing code quality by identifying deeply nested if statements, which can complicate code readability and maintainability.
  • 29-29: Adding testifylint to the list of linters is beneficial for projects using the Testify testing framework, as it can help enforce best practices and identify common mistakes in test code.

.golangci.yml Outdated
- name: unused-parameter # Disabled in favour of unparam.
disabled: true
- name: unhandled-error # enable later, currently covered by errcheck
- name: unhandled-error
Copy link
Contributor

Choose a reason for hiding this comment

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

The explicit disabling of the unhandled-error rule with specific arguments indicates a targeted approach to ignore unhandled errors from certain functions. While this can be useful for reducing noise from known benign unhandled errors, it's important to ensure that this does not inadvertently mask genuine issues. Consider reviewing these exceptions periodically to ensure they remain valid.

Consider adding a comment explaining the rationale behind each ignored function to ensure future maintainability and understanding of these exceptions.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 421d82d and 807f47d.
Files selected for processing (50)
  • .golangci.yml (3 hunks)
  • app/test_helpers.go (1 hunks)
  • app/tps_counter_test.go (1 hunks)
  • cmd/quicksilverd/root.go (1 hunks)
  • icq-relayer/pkg/runner/run.go (1 hunks)
  • server/config/config.go (1 hunks)
  • test/simulation/simtypes/rand.go (1 hunks)
  • third-party-chains/osmosis-types/gamm/pool-models/balancer/pool_asset.go (1 hunks)
  • third-party-chains/osmosis-types/osmomath/decimal.go (1 hunks)
  • third-party-chains/osmosis-types/osmomath/int.go (1 hunks)
  • third-party-chains/osmosis-types/osmoutils/cache_ctx.go (1 hunks)
  • third-party-chains/osmosis-types/osmoutils/slice_helper.go (1 hunks)
  • third-party-chains/umee-types/leverage/params.go (5 hunks)
  • utils/sort.go (2 hunks)
  • wasmbinding/query_plugin_test.go (2 hunks)
  • wasmbinding/test/custom_query_test.go (1 hunks)
  • x/airdrop/keeper/claim_handler.go (1 hunks)
  • x/airdrop/keeper/zonedrop.go (4 hunks)
  • x/airdrop/module.go (6 hunks)
  • x/airdrop/types/airdrop.go (1 hunks)
  • x/airdrop/types/msgs.go (2 hunks)
  • x/airdrop/types/params.go (1 hunks)
  • x/airdrop/types/proposals.go (1 hunks)
  • x/claimsmanager/keeper/abci.go (1 hunks)
  • x/claimsmanager/keeper/hooks.go (1 hunks)
  • x/claimsmanager/keeper/keeper.go (1 hunks)
  • x/claimsmanager/keeper/keeper_test.go (1 hunks)
  • x/claimsmanager/module.go (4 hunks)
  • x/claimsmanager/types/params.go (1 hunks)
  • x/epochs/types/identifier.go (1 hunks)
  • x/interchainquery/genesis_test.go (1 hunks)
  • x/interchainquery/keeper/keeper.go (1 hunks)
  • x/interchainquery/keeper/keeper_test.go (1 hunks)
  • x/interchainquery/keeper/queries.go (1 hunks)
  • x/interchainquery/types/callbacks.go (1 hunks)
  • x/interchainstaking/ibc_module.go (3 hunks)
  • x/interchainstaking/keeper/callbacks.go (1 hunks)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (5 hunks)
  • x/interchainstaking/keeper/keeper_test.go (1 hunks)
  • x/interchainstaking/types/delegation.go (1 hunks)
  • x/interchainstaking/types/params.go (3 hunks)
  • x/interchainstaking/types/proposals_test.go (2 hunks)
  • x/lsmtypes/msg.go (9 hunks)
  • x/mint/types/params.go (6 hunks)
  • x/participationrewards/keeper/callbacks.go (1 hunks)
  • x/participationrewards/keeper/distribution.go (2 hunks)
  • x/participationrewards/types/params.go (2 hunks)
  • x/participationrewards/types/proposals_test.go (2 hunks)
  • x/supply/keeper/keeper.go (1 hunks)
  • x/tokenfactory/types/params.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .golangci.yml
Additional comments: 95
x/claimsmanager/keeper/abci.go (1)
  • 8-8: The change to make BeginBlocker a static function (by removing its receiver) shifts how it interacts with the Keeper's state and methods. Ensure this aligns with the intended design and usage within the module.
x/interchainquery/types/callbacks.go (1)
  • 8-8: Changing the parameter type from interface{} to any in the AddCallback method improves readability and aligns with modern Go practices. Good modernization effort.
x/epochs/types/identifier.go (1)
  • 8-8: Changing the parameter type from interface{} to any in ValidateEpochIdentifierInterface improves readability and aligns with modern Go practices. Good modernization effort.
utils/sort.go (2)
  • 10-10: Changing the type constraint from interface{} to any in the Keys function aligns with modern Go practices and improves code readability.
  • 30-30: Changing the type constraint from interface{} to any in the Unique function aligns with modern Go practices and improves code readability.
third-party-chains/osmosis-types/osmoutils/slice_helper.go (1)
  • 17-17: Changing the type constraint from interface{} to any in the Filter function aligns with modern Go practices and improves code readability.
x/airdrop/types/params.go (2)
  • 25-25: Modifying the receiver type to be anonymous in the ParamSetPairs method is a stylistic change that emphasizes the method does not rely on the receiver's state.
  • 32-32: Modifying the receiver type to be anonymous in the Validate method is a stylistic change that emphasizes the method does not rely on the receiver's state.
third-party-chains/osmosis-types/gamm/pool-models/balancer/pool_asset.go (1)
  • 44-44: The change from (interface{}, error) to (any, error) in the MarshalYAML method's return type is a good readability improvement, aligning with Go's newer conventions. Ensure this change is consistently applied across the codebase where applicable.
x/claimsmanager/keeper/keeper_test.go (1)
  • 47-47: The modification to use an anonymous receiver in the GetQuicksilverApp method is acceptable and can improve readability when the receiver is not used within the method. Ensure this stylistic choice is consistently applied across the codebase where appropriate.
x/airdrop/types/msgs.go (4)
  • 33-33: The use of an anonymous receiver in the Route() method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
  • 36-36: The use of an anonymous receiver in the Type() method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
  • 102-102: The use of an anonymous receiver in the Route() method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
  • 105-105: The use of an anonymous receiver in the Type() method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
x/airdrop/types/airdrop.go (1)
  • 15-27: The refactoring of validation functions for the ZoneDrop struct and the introduction of the validateActionWeights function are good improvements to enhance the validation logic. Ensure these changes are thoroughly tested to confirm they work as intended.
x/interchainstaking/ibc_module.go (3)
  • 79-79: The use of an anonymous receiver in the OnChanOpenConfirm method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
  • 88-88: The use of an anonymous receiver in the OnChanCloseInit method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
  • 108-108: The use of an anonymous receiver in the OnRecvPacket method is a good stylistic choice for readability when the receiver is not used within the method. Ensure this approach is consistently applied across the codebase where appropriate.
x/participationrewards/types/proposals_test.go (2)
  • 160-160: The change from interface{} to any for the sink variable in the benchmarking function is a good readability improvement, aligning with Go's newer conventions. Ensure this change is consistently applied across the codebase where applicable.
  • 188-188: The update to assign nil to sink using any(nil) instead of interface{}(nil) is consistent with the previous change and improves readability. Ensure this approach is consistently applied across the codebase where appropriate.
server/config/config.go (1)
  • 43-43: The change from interface{} to any in the AppConfig function signature is a good readability improvement, aligning with Go's newer conventions. Ensure this change is consistently applied across the codebase where applicable.
third-party-chains/umee-types/leverage/params.go (5)
  • 94-94: The change from interface{} to any in the validateLiquidationThreshold function is a modernization of Go's type system introduced in Go 1.18. This change enhances readability and aligns with current best practices.
  • 111-111: The update from interface{} to any in the validateMinimumCloseFactor function is correctly applied and follows the modern Go conventions introduced with type parameters.
  • 127-127: Changing the parameter type from interface{} to any in the validateOracleRewardFactor function is appropriate and leverages the latest Go language features for improved clarity.
  • 143-143: The modification in the validateSmallLiquidationSize function to use any instead of interface{} is correctly implemented, making the code more idiomatic to recent Go versions.
  • 156-156: The transition from interface{} to any in the validateDirectLiquidationFee function is properly executed, aligning with modern Go type system practices.
wasmbinding/test/custom_query_test.go (1)
  • 79-79: Updating the response parameter type to any in the queryCustom function is a valid use of Go's type parameters feature, enhancing the function's flexibility without compromising type safety due to the subsequent type assertion inside the function.
x/interchainstaking/types/params.go (3)
  • 128-128: The change from interface{} to any in the validateBoolean function is correctly applied, aligning with Go's modern type system enhancements.
  • 137-137: Updating the parameter type to any in the validatePositiveInt function is appropriate and leverages Go's type parameters for improved code clarity.
  • 149-149: The modification in the validateNonNegativeDec function to use any instead of interface{} is correctly implemented, making the code more idiomatic to recent Go versions.
test/simulation/simtypes/rand.go (1)
  • 191-191: The update in the RandSelect function to use any for the type parameter is a correct application of Go's type parameters, enhancing the function's flexibility and readability.
x/mint/types/params.go (6)
  • 108-108: The change from interface{} to any in the validateMintDenom function enhances type clarity without affecting functionality.
  • 120-120: The change from interface{} to any in the validateGenesisEpochProvisions function is a good practice for improving code readability and type safety.
  • 133-133: Updating the parameter type to any in validateReductionPeriodInEpochs aligns with modern Go practices, enhancing code clarity.
  • 146-146: The parameter type change to any in validateReductionFactor is consistent with Go's latest type recommendations, improving code readability.
  • 163-163: Changing the parameter type to any in validateDistributionProportions is a positive step towards clearer and more modern Go code.
  • 193-193: The update to any in validateMintingRewardsDistributionStartEpoch aligns with Go's type system improvements, enhancing code clarity.
x/airdrop/keeper/zonedrop.go (4)
  • 11-11: Removing the receiver from GetZoneDropAccountAddress makes it a static method. Ensure all calls to this method are updated accordingly and consider if access to Keeper's state is required.
  • 102-102: Making IsActiveZoneDrop a static method could impact its functionality if it previously relied on the Keeper's state. Verify that the method's logic remains correct without access to the Keeper's state.
  • 132-132: By removing the receiver from IsFutureZoneDrop, ensure that all its usages are updated to reflect this change. Also, confirm that no Keeper state is needed for its logic.
  • 161-161: The change to make IsExpiredZoneDrop static requires verification to ensure it does not rely on Keeper's state and that all calls to it are correctly updated.
x/interchainstaking/types/proposals_test.go (2)
  • 234-234: Updating the declaration of sink from interface{} to any in the test file is a positive change for type clarity and aligns with modern Go practices.
  • 259-259: Changing the assignment of sink to any(nil) is consistent with the updated type declaration and maintains the test's functionality.
app/test_helpers.go (1)
  • 35-35: The update to return type any in the Get method of EmptyAppOptions is a good practice for improving code readability and type safety.
x/participationrewards/keeper/distribution.go (6)
  • 24-24: Returning nil directly in case of an error is a good practice for functions that return a pointer, slice, map, or channel along with an error. However, since TokenValues is a map type and not a pointer, this change is correct and improves clarity by explicitly indicating that no value is returned in case of an error.
  • 34-34: Initializing TokenValues using make(TokenValues) is a standard practice in Go for initializing maps. This change ensures that tvs is not nil and can have key-value pairs added to it without causing a runtime panic.
  • 45-46: The type assertion pool, ok := ipool.(*types.OsmosisPoolProtocolData) is crucial for ensuring that the unmarshaled ProtocolData is of the expected type. The subsequent check if !ok || len(pool.Denoms) != 2 is a good practice to validate the data integrity and the expected structure of the pool data.
  • 59-60: Checking the existence of a zone using zone, ok := k.icsKeeper.GetZone(ctx, pool.Denoms[ibcDenom].ChainID) and immediately returning if the zone is not found or if the denom does not match the zone's base denom is a good defensive programming practice. It ensures that only valid data is processed further.
  • 67-70: The check if !isBasePair || pool.PoolData == nil followed by returning true to stop further iteration is a good practice for handling invalid or incomplete data. This prevents potential runtime errors or incorrect calculations by ensuring that only pools with valid base pairs and non-nil pool data are processed.
  • 78-82: The error handling for value, err := gammPool.SpotPrice(ctx, baseIBCDenom, queryIBCDenom) is correctly implemented. If an error occurs while calculating the spot price, it logs the error and returns true to stop further processing. This ensures that errors are handled gracefully and do not disrupt the overall execution flow.
x/interchainquery/keeper/keeper_test.go (1)
  • 39-39: Removing the receiver parameter name in the function signature of GetSimApp simplifies the method signature and is acceptable since the receiver is not used within the method. This change adheres to Go's convention of omitting receiver names when they are unused, contributing to cleaner code.
x/claimsmanager/module.go (5)
  • 51-51: Removing the receiver name from the method declaration in RegisterInterfaces simplifies the signature since the receiver is not used within the method. This adheres to Go's convention of omitting receiver names when they are unused, which helps maintain cleaner and more concise code.
  • 81-81: Removing the receiver name from the method declaration in GetTxCmd follows the same rationale as above, improving code cleanliness without affecting functionality.
  • 111-111: Similarly, removing the receiver name from RegisterInvariants in the AppModule struct where the receiver is not used is a good practice for keeping the code concise and readable.
  • 114-114: The removal of the receiver name from Route in the AppModule struct is consistent with the convention of omitting unused receiver names, contributing to cleaner code.
  • 124-124: The change in LegacyQuerierHandler to remove the receiver name is appropriate given that the receiver is not utilized within the method. This keeps the codebase lean and adheres to Go's coding conventions.
x/airdrop/module.go (5)
  • 52-52: Updating the receiver name in RegisterInterfaces to AppModuleBasic from a shorter or non-existent name improves readability and consistency across the module. It makes it clearer which struct the method belongs to, especially in larger files or projects where multiple structs might define similar methods.
  • 85-85: The change in receiver name for GetTxCmd to AppModuleBasic aligns with the goal of improving code clarity and consistency within the module. This change helps in identifying the method's association with its struct more easily.
  • 120-120: Changing the receiver name in Route to AppModule from a shorter name enhances the method's readability and makes it easier to understand the method's scope and association. This is a positive change towards maintaining a consistent and clear codebase.
  • 130-130: The update in receiver name for LegacyQuerierHandler to AppModule is beneficial for code clarity, making it immediately apparent which struct the method is associated with. This is a good practice for code maintainability and readability.
  • 161-161: The receiver name change in BeginBlock to AppModule is consistent with the other changes aimed at improving code clarity. It helps in quickly identifying the struct to which the method belongs, contributing to better code organization.
x/interchainstaking/types/delegation.go (1)
  • 101-102: The updated logic in SetForValoper for directly updating the intent if the valoper is found is clear and straightforward. This change should improve the efficiency of intent updates.
third-party-chains/osmosis-types/osmomath/int.go (1)
  • 374-374: Changing the return type of MarshalYAML from interface{} to any is a good modernization effort, making the code more readable without affecting functionality.
cmd/quicksilverd/root.go (1)
  • 204-204: Updating the return type of initAppConfig from interface{} to any aligns with modern Go practices and improves code readability. This change is consistent and beneficial.
wasmbinding/query_plugin_test.go (2)
  • 48-48: The use of the any type for responseProtoStruct in test cases improves flexibility but requires careful type assertions when used. Ensure that type assertions are properly handled to avoid runtime panics.
  • 227-227: Similarly, the use of the any type for responseProtoStruct in the TestDeterministicJsonMarshal test cases enhances flexibility. It's crucial to handle type assertions correctly to prevent runtime errors.
x/airdrop/keeper/claim_handler.go (3)
  • 340-363: Refactoring the getClaimAmountAndUpdateRecord function to handle summable deposits and single actions separately improves clarity and maintainability. However, ensure that the error handling and state updating logic are thoroughly tested to prevent any regressions.
  • 365-383: The introduction of processSummableDeposits to handle summable deposit actions is a good practice for code modularity and readability. It's important to validate the correctness of the logic, especially the loop and conditionals, to ensure accurate claim amount calculation.
  • 385-396: The processSingleAction function simplifies the handling of non-summable actions, making the code easier to understand and maintain. As with other changes, thorough testing is essential to confirm its correct behavior.
x/participationrewards/keeper/callbacks.go (1)
  • 61-61: The change from interface{} to any for the AddCallback function parameter is a good use of Go 1.18's new features for improved readability. Ensure that the project's Go version requirement (at least 1.18) is clearly documented to inform contributors of the language version requirements.
x/lsmtypes/msg.go (18)
  • 52-52: Removing the receiver name in the Route method signature simplifies the code and improves readability without affecting functionality.
  • 55-55: Removing the receiver name in the Type method signature is a good practice for methods where the receiver is not used, enhancing code readability.
  • 94-94: Omitting the receiver name in the Route method signature for MsgTokenizeShares is consistent with Go best practices, improving code simplicity.
  • 97-97: The removal of the receiver name in the Type method signature for MsgTokenizeShares enhances readability and maintains code quality.
  • 147-147: Simplifying the Route method signature for MsgRedeemTokensForShares by removing the receiver name is a positive change for code readability.
  • 150-150: Removing the receiver name in the Type method signature for MsgRedeemTokensForShares follows Go best practices for unused receivers, improving readability.
  • 195-195: The omission of the receiver name in the Route method signature for MsgTransferTokenizeShareRecord simplifies the code and is a good practice.
  • 198-198: Removing the receiver name in the Type method signature for MsgTransferTokenizeShareRecord enhances code readability and is a positive change.
  • 237-237: Omitting the receiver name in the Route method signature for MsgDisableTokenizeShares is consistent with Go best practices and improves readability.
  • 240-240: The removal of the receiver name in the Type method signature for MsgDisableTokenizeShares simplifies the code and enhances readability.
  • 276-276: Simplifying the Route method signature for MsgEnableTokenizeShares by removing the receiver name is a good practice for code readability.
  • 279-279: Removing the receiver name in the Type method signature for MsgEnableTokenizeShares follows Go best practices for unused receivers, improving readability.
  • 316-316: The omission of the receiver name in the Route method signature for MsgValidatorBond simplifies the code and is consistent with Go best practices.
  • 319-319: Removing the receiver name in the Type method signature for MsgValidatorBond enhances code readability and is a positive change.
  • 355-355: Simplifying the Route method signature for MsgWithdrawTokenizeShareRecordReward by removing the receiver name is a good practice for code readability.
  • 356-356: Removing the receiver name in the Type method signature for MsgWithdrawTokenizeShareRecordReward enhances code readability and maintains code quality.
  • 389-389: Omitting the receiver name in the Route method signature for MsgWithdrawAllTokenizeShareRecordReward is consistent with Go best practices and improves readability.
  • 391-391: The removal of the receiver name in the Type method signature for MsgWithdrawAllTokenizeShareRecordReward simplifies the code and enhances readability.
third-party-chains/osmosis-types/osmomath/decimal.go (1)
  • 703-703: The change from returning interface{} to any in the MarshalYAML function is a modernization of the Go codebase, leveraging the any type introduced in Go 1.18 as a more readable alias for interface{}. This change improves code readability without affecting functionality, as any and interface{} are interchangeable. This update aligns with best practices for Go code written using Go 1.18 or later.
icq-relayer/pkg/runner/run.go (1)
  • 548-548: The change from map[string]interface{} to map[string]any for the params map in the Tx function improves code readability by using the any type introduced in Go 1.18. This change should not affect functionality but ensures the codebase is up-to-date with recent Go language enhancements. Ensure that all related type assertions and interface implementations are reviewed to confirm compatibility with this change.
x/interchainstaking/keeper/callbacks.go (1)
  • 65-65: The change from interface{} to any in the AddCallback function signature is a modernization effort aligning with Go 1.18's introduction of type parameters, making the code more readable and idiomatic. However, it's crucial to ensure that all calls to AddCallback throughout the codebase are reviewed to confirm compatibility with this change. The use of any instead of interface{} does not affect the functionality but improves clarity.
x/interchainstaking/keeper/keeper_test.go (4)
  • 62-62: Removing the receiver parameter name in the GetQuicksilverApp method signature improves the method's readability by indicating that the receiver is not used within the method. This change aligns with Go best practices for unused receiver variables.
  • 62-62: The method GetQuicksilverApp is correctly modified to indicate that the receiver is not used within its body by removing the receiver's name. This is a good practice in Go when the method does not utilize the receiver, enhancing clarity.
  • 62-62: The change to the GetQuicksilverApp method's receiver is a minor but positive adjustment for clarity, as it clearly indicates that the receiver is not utilized within the method. This adheres to Go's idiomatic way of handling unused variables.
  • 62-62: The adjustment to the GetQuicksilverApp method's receiver parameter is a good practice for Go code, especially when the receiver is not needed. This change is clear and does not impact the functionality of the method.

Comment on lines +105 to +106
vi = append(vi, intent)
return vi.Sort()
Copy link
Contributor

Choose a reason for hiding this comment

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

Appending the new intent and then sorting the list every time a new intent is added could potentially be inefficient for large lists. Consider if maintaining the list in sorted order at all times is necessary, or if there are more efficient ways to manage this list.

// Instead of sorting the entire list every time a new intent is added,
// you could insert the new intent in the correct position to maintain order.

x/interchainstaking/keeper/ibc_packet_handlers.go Outdated Show resolved Hide resolved
@@ -50,7 +50,7 @@
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
func (Keeper) Logger(ctx sdk.Context) log.Logger {
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process reveals that the Logger function's usage across the codebase is inconsistent with the change to make it a static method by removing the receiver name k. The function is widely used as an instance method, indicating that it operates in the context of specific keeper instances, which is essential for logging module-specific information. Changing Logger to a static method could disrupt this context, potentially leading to issues in logging. It's crucial to ensure that the Logger function's design and usage align with the intended logging practices and module architecture.

Analysis chain

Removing the receiver name k from the Logger function signature in the Keeper struct makes it a static method. This change should be carefully considered, as it alters how the function can be called and may impact its usage throughout the codebase. Ensure that this change aligns with the intended design and usage patterns of the Logger function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usages of the Logger function to ensure they are correctly updated.
rg --type go 'Logger\('

Length of output: 52336

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 807f47d and 47bb099.
Files selected for processing (5)
  • wasmbinding/message_plugin.go (1 hunks)
  • x/interchainquery/keeper/keeper.go (2 hunks)
  • x/interchainstaking/keeper/callbacks.go (3 hunks)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (4 hunks)
  • x/interchainstaking/transfer_middleware.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainquery/keeper/keeper.go
Additional comments: 7
x/interchainstaking/keeper/callbacks.go (5)
  • 65-65: The AddCallback function signature has been changed to accept a parameter of type any instead of interface{}. While this change aligns with Go's more recent type parameter features introduced in Go 1.18, it's important to ensure that all calls to AddCallback throughout the codebase have been updated to reflect this change. Additionally, since any is essentially an alias for interface{}, this change does not impact the function's ability to accept any type of argument but does improve readability and modernizes the codebase.
  • 170-175: The logic within DelegationCallback to decide whether to remove a delegation or process it is clear and straightforward. The use of shouldRemoveDelegation to determine if a delegation should be removed based on its shares being nil or zero is a good practice, ensuring that only valid delegations are processed further. The separation of concerns by having handleDelegationRemoval and processDelegation handle specific tasks based on this condition improves code readability and maintainability.
  • 177-179: The shouldRemoveDelegation function correctly checks if the delegation's shares are either nil or zero, which are valid conditions for removing a delegation. This function encapsulates the logic for this check neatly, making the code more modular and easier to understand.
  • 181-202: The handleDelegationRemoval function performs several operations, including parsing the delegation key, encoding addresses, and removing the delegation if it exists. It's important to ensure that error handling is consistent and that any potential errors from helper functions like ParseStakingDelegationKey and EncodeAddressToBech32 are handled appropriately. This function demonstrates good error handling practices by returning errors immediately when they occur, which helps in maintaining the robustness of the code.
  • 162-207: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [204-216]

The processDelegation function demonstrates a clear flow of logic for processing a delegation, including fetching the validator by address and updating the delegation record. Error handling is appropriately implemented, with errors being returned immediately when they occur. This function's structure and error handling practices contribute to the maintainability and robustness of the code.

x/interchainstaking/keeper/ibc_packet_handlers.go (2)
  • 647-652: The error handling logic within HandleBeginRedelegate for the case where srcDelegation.Amount.SafeSub(redelegateMsg.Amount) results in a "negative coin amount" error is a pragmatic approach to deal with potential race conditions. However, it's crucial to ensure that this handling does not mask other issues that could lead to inconsistent state or unexpected behavior.

While the current approach logs the occurrence of a negative coin amount, consider adding additional monitoring or alerting mechanisms to track these occurrences. Frequent hits on this condition could indicate deeper issues with the state management or race conditions that need to be addressed.

  • 1080-1109: The HandleUpdatedWithdrawAddress function correctly updates the withdrawal address for different account types (DelegationAddress, PerformanceAddress, DepositAddress) based on the delegator address provided in the MsgSetWithdrawAddress. This change enhances the flexibility of the system by allowing updates to withdrawal addresses across different account types.

The implementation follows a clear and logical structure, making it easy to understand and maintain. The use of type assertions and checks for the existence of zones for different account types before attempting to update the withdrawal address is a good practice that ensures the robustness of the code.

Comment on lines +97 to +113
if !ack.Success() {
return ack
}

_, found := im.keeper.GetZoneForWithdrawalAccount(ctx, data.Sender)
if !found {
return ack
}

if data.Receiver != im.keeper.AccountKeeper.GetModuleAddress(types.ModuleName).String() {
return ack
}

im.keeper.Logger(ctx).Info("MsgTransfer to ics module account from withdrawal address")
err := im.keeper.HandleMsgTransfer(ctx, data, utils.DeriveIbcDenom(packet.DestinationPort, packet.DestinationChannel, packet.SourcePort, packet.SourceChannel, data.Denom))
if err != nil {
im.keeper.Logger(ctx).Error("unable to disperse rewards", "error", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

The refactoring in the OnRecvPacket method introduces a more structured approach to handling conditions based on the success of ack. This change improves readability and maintainability by using early returns for specific conditions not met, which aligns with best practices for reducing nesting and complexity. However, ensure that all scenarios previously covered are still adequately handled with the new logic structure. Additionally, consider adding more detailed logging for each early return case to aid in debugging and operational monitoring.

Comment on lines +45 to +53

switch {
case contractMsg.CreateDenom != nil:
return m.createDenom(ctx, contractAddr, contractMsg.CreateDenom)
}
if contractMsg.MintTokens != nil {
case contractMsg.MintTokens != nil:
return m.mintTokens(ctx, contractAddr, contractMsg.MintTokens)
}
if contractMsg.ChangeAdmin != nil {
case contractMsg.ChangeAdmin != nil:
return m.changeAdmin(ctx, contractAddr, contractMsg.ChangeAdmin)
}
if contractMsg.BurnTokens != nil {
case contractMsg.BurnTokens != nil:
Copy link
Contributor

Choose a reason for hiding this comment

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

The refactoring to use a switch statement in the DispatchMsg method for handling different types of TokenFactoryMsg is a positive change that enhances the clarity and maintainability of the code. This approach makes it easier to understand the flow of logic and add new message types in the future. However, ensure that each case in the switch statement properly handles errors and returns meaningful messages to the caller. Additionally, consider adding default case handling to catch any unsupported message types, which could improve error reporting and robustness.

x/interchainstaking/keeper/ibc_packet_handlers.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 47bb099 and 48c466f.
Files selected for processing (1)
  • x/interchainstaking/keeper/callbacks.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/callbacks.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 48c466f and 088e385.
Files selected for processing (2)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (5 hunks)
  • x/participationrewards/keeper/submodule_osmosis.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/ibc_packet_handlers.go
Additional comments: 1
x/participationrewards/keeper/submodule_osmosis.go (1)
  • 73-84: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [77-110]

The updated ValidateClaim function introduces a switch statement to handle different proof types, specifically adding a case for types.ProofTypeBank. This change aims to improve the validation process by correctly initializing the lock variable based on the proof type. Here are some observations and recommendations:

  1. Error Handling Consistency: The error handling within the switch statement is consistent and correctly returns errors when encountered. This is good practice and ensures that the function fails early if there are issues with the proof data.

  2. Use of strconv.Atoi for Pool ID Parsing: The use of strconv.Atoi to parse the pool ID from the poolDenom string is appropriate. However, consider adding a comment explaining why this parsing is necessary, as it might not be immediately clear to other developers why the pool ID is extracted from the poolDenom.

  3. Lock Initialization for Bank Proofs: The initialization of the lock variable for bank proofs using osmolockup.NewPeriodLock is a significant improvement. It ensures that the lock is correctly set up with the necessary information, such as the pool ID, address, and coins. This approach enhances the clarity and correctness of the validation process.

  4. Validation of Lockup Owner: The validation step where the lockup owner's address is decoded and compared to the msg.UserAddress is crucial for ensuring that the proof submitted is valid for the user making the claim. This check enhances the security of the claim submission process by preventing users from submitting proofs that do not belong to them.

  5. Amount Calculation and Error Handling: The final calculation of the applicable tokens in the pool and the subsequent checks for nil or negative amounts are well-handled. These checks ensure that the amount returned is valid and prevent potential issues with token calculations.

Overall, the changes to the ValidateClaim function are well-implemented and improve the validation process for claims. The introduction of the switch statement and the specific handling of bank proofs enhance the function's clarity, correctness, and security.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 088e385 and 0f13b3f.
Files selected for processing (4)
  • x/interchainquery/genesis_test.go (1 hunks)
  • x/interchainquery/keeper/keeper.go (2 hunks)
  • x/interchainquery/keeper/keeper_test.go (1 hunks)
  • x/interchainquery/keeper/queries.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • x/interchainquery/genesis_test.go
  • x/interchainquery/keeper/keeper.go
  • x/interchainquery/keeper/keeper_test.go
  • x/interchainquery/keeper/queries.go

@faddat faddat changed the title Update .golangci.yml chore: use the nested if's linter to reduce complexity globally Feb 23, 2024
@joe-bowman
Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: 690bd5c
✅ Preview: https://pr-1158.app-dev.quicksilver.zone
🔍 Inspect: https://vercel.com/quicksilver/quicksilver/ERZimtwTUWqm3Nn3op5sAQwGsiKb

View Workflow Logs

@joe-bowman
Copy link
Contributor

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!

@tuantran1702
Copy link
Contributor

tuantran1702 commented May 15, 2024

We should enable this linter after #1202 done to avoid conflicts. For now this PR can be closed and I will surely go over this later sir @faddat

@faddat
Copy link
Contributor Author

faddat commented May 23, 2024

Great idea. I'm going to close it.

@faddat faddat closed this May 23, 2024
@joe-bowman joe-bowman deleted the faddat-patch-2 branch November 18, 2024 18:50
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