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(lint): golang-client lint errors #3924

Merged
merged 3 commits into from
Sep 30, 2024

Conversation

kobakaku
Copy link
Contributor

@kobakaku kobakaku commented Sep 30, 2024

Closes #3919

Overview

Fix the lint errors of golangci-lint.
Merge this PR to this branch.

Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on updating linter configurations, enhancing test coverage, and improving error handling. Key modifications include the removal of deprecated linters, the addition of new test cases for transaction prioritization and data availability headers, and adjustments to error message formatting in the keeper package.

Changes

File Path Change Summary
.golangci.yml Removed exportloopref, added copyloopvar, and set max-func-lines for nakedret to 0.
app/test/priority_test.go Implemented a test suite for transaction prioritization by gas price with several helper methods.
pkg/da/data_availability_header_test.go Added tests for DataAvailabilityHeader, enhancing coverage for edge cases and error handling.
x/blob/client/testutil/integration_test.go Introduced a test suite for blob transactions with multiple test cases covering various scenarios.
x/blobstream/keeper/keeper_data_commitment.go Improved error handling by simplifying error message formatting.
x/blobstream/keeper/keeper_valset_test.go Added new test cases for validation set and attestation nonce handling, enhancing test robustness.
x/mint/client/testutil/suite_test.go Removed unnecessary variable shadowing in test methods for clarity.
x/mint/simulation/decoder_test.go Simplified TestDecodeStore by removing unnecessary variable reassignment.

Assessment against linked issues

Objective Addressed Explanation
Address lint complaints regarding non-constant format strings ( #3919)

Possibly related PRs

Suggested labels

bug, testing


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@kobakaku kobakaku marked this pull request as draft September 30, 2024 14:22
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
x/blobstream/keeper/keeper_data_commitment.go (2)

139-139: Improved error handling and suggestion for consistency

The change from using fmt.Sprintf to directly formatting the error message in errors.Wrapf is a good improvement. It makes the code more concise and addresses the lint error related to non-constant format strings in errors.Wrapf calls.

For consistency, consider updating the error message to match the style used in the GetLatestDataCommitment method:

-			return false, errors.Wrapf(types.ErrAttestationNotFound, "nonce %d", i)
+			return false, errors.Wrapf(types.ErrAttestationNotFound, "nonce %d", i)

Line range hint 9-9: Address TODO: Add unit tests for all keepers

The TODO comment indicates that unit tests are missing for the keepers. While this is not directly related to the current PR's objectives, addressing this would significantly improve the code quality and maintainability.

Would you like assistance in creating a GitHub issue to track the task of adding unit tests for all keepers? This could help ensure that this important task is not overlooked in future development efforts.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 21e78b9 and 51c4139.

📒 Files selected for processing (8)
  • .golangci.yml (1 hunks)
  • app/test/priority_test.go (0 hunks)
  • pkg/da/data_availability_header_test.go (0 hunks)
  • x/blob/client/testutil/integration_test.go (0 hunks)
  • x/blobstream/keeper/keeper_data_commitment.go (2 hunks)
  • x/blobstream/keeper/keeper_valset_test.go (0 hunks)
  • x/mint/client/testutil/suite_test.go (0 hunks)
  • x/mint/simulation/decoder_test.go (0 hunks)
💤 Files with no reviewable changes (6)
  • app/test/priority_test.go
  • pkg/da/data_availability_header_test.go
  • x/blob/client/testutil/integration_test.go
  • x/blobstream/keeper/keeper_valset_test.go
  • x/mint/client/testutil/suite_test.go
  • x/mint/simulation/decoder_test.go
🔇 Additional comments (3)
.golangci.yml (2)

7-7: LGTM: Addition of 'copyloopvar' linter

The addition of the 'copyloopvar' linter is a good replacement for the removed 'exportloopref' linter. This change will help catch potential issues with loop variables being inadvertently shared across iterations, which can lead to subtle bugs. This aligns well with the PR objective of improving code quality and fixing lint errors.


Line range hint 18-20: Approve stricter 'nakedret' settings, but verify impact

Setting 'max-func-lines' to 0 for the 'nakedret' linter effectively bans all naked returns in functions. This can improve code readability and reduce potential errors. However, this is a significant change that might affect existing code.

To ensure this change doesn't cause widespread issues, please run the following script to check for potential impacts:

This script will help you identify and quantify the functions that might need to be updated due to this linter change.

✅ Verification successful

The stricter 'nakedret' settings have been verified and no issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for naked returns in the codebase that might be affected by the new 'nakedret' setting

# Search for functions with naked returns
echo "Functions with naked returns:"
ast-grep --lang go --pattern 'func $name($params) $return_type {
  $$$
  return
}'

# Count the occurrences
count=$(ast-grep --lang go --pattern 'func $name($params) $return_type {
  $$$
  return
}' | wc -l)

echo "Total number of functions with naked returns: $count"

Length of output: 363

x/blobstream/keeper/keeper_data_commitment.go (1)

112-112: Improved error handling implementation

The change from using fmt.Sprintf to directly formatting the error message in errors.Wrapf is a good improvement. It makes the code more concise and addresses the lint error related to non-constant format strings in errors.Wrapf calls.

@rootulp rootulp added the backport:v2.x PR will be backported automatically to the v2.x branch upon merging label Sep 30, 2024
@rootulp
Copy link
Collaborator

rootulp commented Sep 30, 2024

Added backport to v2.x label b/c I originally noticed these lint issues were on v2.x branch.

@rootulp rootulp enabled auto-merge (squash) September 30, 2024 15:50
@rootulp rootulp merged commit 363a8c5 into celestiaorg:main Sep 30, 2024
30 of 31 checks passed
mergify bot pushed a commit that referenced this pull request Sep 30, 2024
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->
Closes #3919
## Overview

<!--
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue.
-->
Fix the lint errors of golangci-lint.
Merge this [PR](#3923)
to this branch.

(cherry picked from commit 363a8c5)
rootulp added a commit that referenced this pull request Oct 14, 2024
Closes #3919
## Overview


Fix the lint errors of golangci-lint.
Merge this [PR](#3923)
to this branch.<hr>This is an automatic backport of pull request #3924
done by [Mergify](https://mergify.com).

---------

Co-authored-by: kobakaku <[email protected]>
Co-authored-by: Rootul P <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:v2.x PR will be backported automatically to the v2.x branch upon merging external
Projects
None yet
Development

Successfully merging this pull request may close these issues.

non-constant format string in call to cosmossdk.io/errors.Wrapf
3 participants