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

refactor: enable go-critic #3000

Merged
merged 7 commits into from
Jan 23, 2024
Merged

Conversation

moldis
Copy link
Contributor

@moldis moldis commented Jan 10, 2024

Closes #2987

  • Added gocritics to linter
  • Fixed minor gocritics linter errors

@rootulp rootulp changed the title fix: adding gocritics and fixing lint errors refactor: enable go-critic Jan 10, 2024
@moldis moldis marked this pull request as ready for review January 11, 2024 03:38
Copy link
Contributor

coderabbitai bot commented Jan 11, 2024

Walkthrough

Walkthrough

The changes across the codebase are primarily focused on adopting shorthand assignment operators to enhance code readability and maintainability. The files affected include various .go files where compound assignment operators like +=, -=, /=, and <<= are used to streamline operations. Additionally, the .golangci.yml file has been updated to enable the go-critic linter, ensuring adherence to best practices and cleaner code.

Changes

File(s) Change Summary
.golangci.yml Enabled go-critic linter.
.../data_availability_header.go, .../powers_of_two.go Updated to use <<= operator for left shift assignment.
.../commitment.go, .../nmt_caching_test.go, .../paths.go, .../paths_test.go, .../share_builder.go, .../shares_test.go Modified to use compound assignment operators (+=, -=, /=, ^=).
.../square/square.go Simplified copy function call by removing slice expression.
.../client/testutil/integration_test.go Replaced switch statement with if statement for conditional control flow.
.../types/validator.go Updated bytes.Compare to remove unnecessary slice expressions.
x/upgrade/keeper.go Removed unused parameter and switch statement; unconditionally returns defaultSignalThreshold.

Assessment against linked issues

Objective Addressed Explanation
Enable go-critic in .golangci.yml and address issues reported by go-critic (#2987)
Ensure all shorthand assignment operators are used where applicable for code readability and maintainability
Remove unnecessary slice expressions and simplify conditional control flow
Remove unused parameters and switch statements for cleaner code

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your comments 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@celestia-bot celestia-bot requested a review from a team January 11, 2024 06:21
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It looks like golangci-lint is complaining still so I think a few more changes need to be made before we can merge this.

We're in a transitory phase where we're extracting a few of the files touched in this PR to https://github.com/celestiaorg/go-square. So if we enable go-critic here then we should also enable go-critic in that repo. Eventually the files in this repo that were moved to go-square will be removed.

Created: celestiaorg/go-square#18

.golangci.yml Show resolved Hide resolved
pkg/shares/shares_test.go Outdated Show resolved Hide resolved
x/upgrade/keeper.go Outdated Show resolved Hide resolved
@rootulp rootulp marked this pull request as draft January 11, 2024 18:06
@rootulp
Copy link
Collaborator

rootulp commented Jan 21, 2024

@moldis is this ready for review? It looks like golangci-lint passes here.

@rootulp rootulp marked this pull request as ready for review January 21, 2024 04:45
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the contribution @moldis

Copy link
Collaborator

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

Thanks, Looks good to me too!

Copy link
Member

@ninabarbakadze ninabarbakadze left a comment

Choose a reason for hiding this comment

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

thank you!

@celestia-bot celestia-bot requested a review from a team January 23, 2024 16:04
Comment on lines +32 to +33
func SignalThreshold(_ uint64) Fraction {
return defaultSignalTheshold
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 change to the SignalThreshold function in x/upgrade/keeper.go to always return defaultSignalThreshold and ignore the version parameter could affect the upgrade logic, as the GetVotingPowerThreshold function relies on it to calculate the voting power threshold for upgrades. This threshold previously could vary with the app version, which is no longer the case after the change.

Analysis chain

The SignalThreshold function has been simplified to always return defaultSignalTheshold. This change removes the parameter and the switch statement, which is consistent with the summary. However, it's important to ensure that this change does not affect any other part of the system that might rely on the removed logic.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for usages of SignalThreshold to ensure the change doesn't affect other parts of the system.
rg --type go "SignalThreshold"

Length of output: 269



Script:

#!/bin/bash
# Search for any logic in the keeper.go file that might have depended on the version parameter in SignalThreshold.
rg --type go -C 10 "SignalThreshold" x/upgrade/keeper.go

Length of output: 1761

@rootulp rootulp merged commit cd0a1cd into celestiaorg:main Jan 23, 2024
29 checks passed
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.

Consider enabling go-critic linter
6 participants