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/upgrade golangci-lint to 1.61 #776

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

dangogh
Copy link
Contributor

@dangogh dangogh commented Oct 7, 2024

  • Upgraded golangci-lint to 1.61
  • Added comments to ignore some lint warnings (in particular gosec:G115)
  • Renamed min,max which are predeclared funcs as of Go 1.21
  • linter exportloopref deprecated -- should be replaced with copyloopvar on upgrading to Go 1.22

Summary by CodeRabbit

  • New Features

    • Updated Docker image version for improved linting tools.
    • Introduced a new job for linting proto files and enhanced existing linting jobs for better validation.
    • Added unit tests for validating bounds in the validateBounds function.
  • Bug Fixes

    • Enhanced error handling in the QueryInterpreter function.
  • Documentation

    • Added comments to suppress specific linting warnings across various functions for clarity.
  • Refactor

    • Renamed parameters in the validateBounds function for better readability.
    • Minor adjustments to error messages for improved clarity.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The pull request includes updates to the Makefile and various test files primarily focused on linting adjustments and minor modifications to the build process. Key changes involve updating the Docker image version for GolangCI Lint and adding comments to suppress specific linter warnings across several files. Additionally, the validateBounds function's parameter names have been updated for clarity. Overall, the changes enhance code quality without altering the core functionality or logic.

Changes

File Change Summary
Makefile Updated DOCKER_IMAGE_GOLANG_CI from v1.56 to v1.61; added conditional static linking flags.
.github/workflows/lint.yml Updated lint-go job to use golangci-lint-action v1.61; added command to install jsonlint; modified lint-proto to find changed proto files; expanded lint-generated with documentation generation steps.
x/logic/keeper/features_test.go Added comment to suppress linter warning G115 for limit variable.
x/logic/keeper/grpc_query_ask_test.go Added comment to suppress linter warning G115 for v variable in TestGRPCAsk.
x/logic/keeper/interpreter.go Added comments to suppress linter warning G115 in execute and newInterpreter methods.
x/logic/predicate/string.go Added comments to suppress linter warning G115 for maxLength, totalLen, and return statement.
x/logic/prolog/option.go Added comment to suppress linter warning nilnil in extractOption function.
x/logic/util/prolog.go Modified error handling in QueryInterpreter to include comment for linter warning govet.
x/mint/simulation/proposals.go Added comment to suppress linter warning G115 for params.BlocksPerYear.
x/mint/types/params.go Renamed validateBounds parameters from min, max to minBound, maxBound and updated error messages.
x/mint/types/params_test.go Added unit tests for validateBounds function, including various test cases for validation.

Possibly related PRs

  • Fix/predicate gas consumption #756: The changes in the x/logic/keeper/grpc_query_ask_test.go file involve modifications to test cases related to gas limits, which may indirectly relate to the build process and linting improvements in the main PR, as both involve code quality and execution efficiency.

Suggested reviewers

  • amimart
  • bdeneux

Poem

🐰 In the garden of code, we hop and play,
With linting whispers guiding our way.
Docker images fresh, like morning dew,
Comments to silence the warnings anew.
A dance of parameters, clearer and bright,
In our code's little world, everything's right! 🌼


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>, please review it.
    • 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 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.

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 (1)
x/mint/types/params.go (1)

Line range hint 90-107: Approve changes with a minor suggestion for improvement

The changes to the validateBounds function are well-implemented and address potential naming conflicts with Go 1.21's predeclared min and max functions. The updated function signature and variable names improve code compatibility and clarity.

The error message modification enhances readability.

Consider using more descriptive variable names to further improve code readability:

-func validateBounds(mmin, mmax interface{}) error {
-	vmin, ok := mmin.(*math.LegacyDec)
+func validateBounds(minBound, maxBound interface{}) error {
+	vmin, ok := minBound.(*math.LegacyDec)
 	if !ok {
-		return fmt.Errorf("invalid parameter type: %T", mmin)
+		return fmt.Errorf("invalid parameter type: %T", minBound)
 	}
-	vmax, ok := mmax.(*math.LegacyDec)
+	vmax, ok := maxBound.(*math.LegacyDec)
 	if !ok {
-		return fmt.Errorf("invalid parameter type: %T", mmax)
+		return fmt.Errorf("invalid parameter type: %T", maxBound)
 	}

This change would make the function's purpose even clearer without introducing any functional changes.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4d8205b and 343aa34.

📒 Files selected for processing (10)
  • Makefile (1 hunks)
  • x/logic/keeper/features_test.go (1 hunks)
  • x/logic/keeper/grpc_query_ask_test.go (1 hunks)
  • x/logic/keeper/interpreter.go (2 hunks)
  • x/logic/predicate/string.go (3 hunks)
  • x/logic/prolog/option.go (1 hunks)
  • x/logic/testutil/keeper_mocks.go (2 hunks)
  • x/logic/util/prolog.go (1 hunks)
  • x/mint/simulation/proposals.go (1 hunks)
  • x/mint/types/params.go (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • x/logic/keeper/features_test.go
  • x/logic/keeper/grpc_query_ask_test.go
🧰 Additional context used
🪛 GitHub Check: lint-go
x/logic/keeper/interpreter.go

[failure] 68-68:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)


[failure] 100-100:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)

x/logic/predicate/string.go

[failure] 53-53:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)


[failure] 66-66:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)


[failure] 76-76:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)

x/logic/prolog/option.go

[failure] 14-14:
directive //nolint:nilnil is unused for linter "nilnil" (nolintlint)

x/logic/testutil/keeper_mocks.go

[failure] 41-41:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)


[failure] 70-70:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)

x/logic/util/prolog.go

[failure] 62-62:
directive //nolint:govet is unused for linter "govet" (nolintlint)

x/mint/simulation/proposals.go

[failure] 40-40:
directive //nolint:gosec // disable G115 is unused for linter "gosec" (nolintlint)

🔇 Additional comments (4)
x/logic/util/prolog.go (1)

62-62: Verify the necessity and correctness of the nolint directive

The added //nolint:govet directive appears to be unused according to the static analysis tool. This could indicate that either the govet linter is not raising an issue on this line, or the golangci-lint configuration might not include govet.

To address this, please:

  1. Verify if govet is actually raising an issue on this line without the directive.
  2. Check if govet is included in your golangci-lint configuration.
  3. If the directive is necessary, ensure it's in the correct format (e.g., //nolint:govet or //nolint:vet).

If the directive is indeed unnecessary, consider removing it to keep the code clean.

🧰 Tools
🪛 GitHub Check: lint-go

[failure] 62-62:
directive //nolint:govet is unused for linter "govet" (nolintlint)

Makefile (3)

Line range hint 1-1: Summary of Makefile changes

The main visible change in this Makefile is the update of GolangCI Lint to version 1.61, which aligns with the PR objectives. However, there's a discrepancy between the AI-generated summary and the visible changes:

  1. The summary mentioned an addition to LD_FLAGS for conditional static linking, but this change is not visible in the provided code segment.

To ensure a comprehensive review, please clarify if there are any changes to the LD_FLAGS variable or any other modifications not visible in the provided diff. This will help in assessing the full scope of the changes and their potential impact on the build process.

You can use the following command to show all changes in the Makefile:


Line range hint 1-1: Verify LD_FLAGS changes for static linking

The AI-generated summary mentioned an addition to LD_FLAGS for conditional static linking, but this change is not visible in the provided code segment.

Please confirm if there are any changes to the LD_FLAGS variable related to static linking. If such changes exist, they should be reviewed for correctness and potential impact on the build process.

You can run the following command to check for any changes to LD_FLAGS in the Makefile:


13-13: Approved: GolangCI Lint version update

The update from v1.56 to v1.61 aligns with the PR objective. This change may introduce new linting rules or fix existing issues.

It's recommended to review the changelog for any breaking changes or new features. You can run the following command to check the differences between the two versions:

✅ Verification successful

Verified: DOCKER_IMAGE_GOLANG_CI version update

The DOCKER_IMAGE_GOLANG_CI variable has been successfully updated to golangci/golangci-lint:v1.61, aligning with the PR objective.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch and compare changelogs for v1.56 and v1.61
curl -s https://raw.githubusercontent.com/golangci/golangci-lint/v1.56.0/CHANGELOG.md | sed -n '/## v1.56.0/,/## v1.55.2/p' > /tmp/v1.56.0.md
curl -s https://raw.githubusercontent.com/golangci/golangci-lint/v1.61.0/CHANGELOG.md | sed -n '/## v1.61.0/,/## v1.60.0/p' > /tmp/v1.61.0.md
echo "Changes in v1.61.0 compared to v1.56.0:"
diff /tmp/v1.56.0.md /tmp/v1.61.0.md

Length of output: 527


Script:

#!/bin/bash
# Corrected script to fetch and compare changelogs for v1.56.0 and v1.61.0

# Fetch changelog for v1.56.0
curl -s https://raw.githubusercontent.com/golangci/golangci-lint/v1.56.0/CHANGELOG.md | sed -n '/## v1.56.0/,/## v1.57.0/p' > /tmp/v1.56.0.md

# Fetch changelog for v1.61.0
curl -s https://raw.githubusercontent.com/golangci/golangci-lint/v1.61.0/CHANGELOG.md | sed -n '/## v1.61.0/,/## v1.62.0/p' > /tmp/v1.61.0.md

echo "Changes in v1.61.0 compared to v1.56.0:"
diff /tmp/v1.56.0.md /tmp/v1.61.0.md

Length of output: 379


Script:

#!/bin/bash
# Extract the value of DOCKER_IMAGE_GOLANG_CI from the Makefile

rg '^DOCKER_IMAGE_GOLANG_CI\s*=' Makefile

Length of output: 100

@dangogh dangogh force-pushed the chore/upgrade-golangci-lint branch from 343aa34 to e6cc19a Compare October 7, 2024 19:46
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/logic/util/prolog.go 0.00% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #776      +/-   ##
==========================================
+ Coverage   54.98%   55.42%   +0.43%     
==========================================
  Files          73       73              
  Lines        2966     2966              
==========================================
+ Hits         1631     1644      +13     
+ Misses       1241     1228      -13     
  Partials       94       94              
Files with missing lines Coverage Δ
x/logic/keeper/interpreter.go 92.92% <100.00%> (ø)
x/logic/predicate/string.go 81.69% <100.00%> (ø)
x/logic/prolog/option.go 60.97% <ø> (ø)
x/mint/simulation/proposals.go 100.00% <100.00%> (ø)
x/mint/types/params.go 21.66% <100.00%> (+21.66%) ⬆️
x/logic/util/prolog.go 0.00% <0.00%> (ø)

@dangogh dangogh force-pushed the chore/upgrade-golangci-lint branch from e6cc19a to 8b313ae Compare October 7, 2024 19:57
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/mint/types/params_test.go (2)

12-15: Consider returning by value instead of pointer.

The toLegacyDec function currently returns a pointer to math.LegacyDec. While this works, it might be safer and more idiomatic to return the value directly:

func toLegacyDec(i int64) math.LegacyDec {
    return math.LegacyNewDec(i)
}

This change would eliminate the risk of nil pointer dereferences and simplify the function. However, if there's a specific reason for using a pointer (e.g., consistency with other parts of the codebase), please disregard this suggestion.


17-89: LGTM: Comprehensive test cases with clear structure.

The Test_validateBounds function is well-structured and covers a wide range of scenarios, including edge cases. The use of table-driven tests with goconvey enhances readability and maintainability.

Minor suggestion: Consider adding a test case for when both bounds are equal (e.g., min = max = 5). This would ensure that the validateBounds function handles this edge case correctly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0154d6b and 9e7cef0.

📒 Files selected for processing (1)
  • x/mint/types/params_test.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
x/mint/types/params_test.go (2)

3-10: LGTM: Imports are appropriate and well-structured.

The imports section is well-organized and includes all necessary libraries for the test file. The use of goconvey for BDD-style testing is a good choice for improving code quality and readability.


1-89: Overall: Well-structured and comprehensive test file.

This new test file for validateBounds function is a valuable addition to the codebase. It aligns well with the PR objectives of improving code quality. The use of table-driven tests and goconvey framework enhances readability and maintainability.

The test cases cover various scenarios, including edge cases, which is crucial for ensuring the robustness of the validateBounds function. The minor suggestions provided earlier (returning by value in the helper function and adding an equal bounds test case) would further improve the file, but they are not critical issues.

Great job on improving the test coverage and code quality!

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

Brilliant! Thanks for this great contribution — a big win for the code quality of our chain! 👍

Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you 🙏

@amimart amimart merged commit 193f7c2 into axone-protocol:main Oct 8, 2024
20 checks passed
@ccamel ccamel linked an issue Oct 8, 2024 that may be closed by this pull request
@coderabbitai coderabbitai bot mentioned this pull request Oct 9, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 22, 2024
4 tasks
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.

👷🏼 Upgrade golangci-lint to the latest version
3 participants