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: remove true comparision #1558

Merged
merged 6 commits into from
Jun 23, 2024

Conversation

TropicalDog17
Copy link
Contributor

@TropicalDog17 TropicalDog17 commented Jun 21, 2024

Description

Remove instances of redundant logical conditions that alway result in true.

Summary by CodeRabbit

  • Refactor
    • Simplified file path handling in the CLI application for better efficiency and readability.
    • Improved the logic for decoding hexadecimal nibbles by removing redundant conditions.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2024

Warning

Review failed

The head commit changed during the review from 2f63c89 to f5912eb.

Walkthrough

The recent updates involve simplifying and optimizing the code in two parts of the Go CLI application. The first change refactors the logic for determining file paths in the JWT commands, reducing redundancy and consolidating file path assignments. The second change enhances the decodeNibble function by removing unnecessary conditions to streamline the decoding of hexadecimal nibbles.

Changes

File Change Summary
mod/cli/pkg/commands/jwt/jwt.go Simplified file path logic by removing redundant checks and consolidating the file path assignment. Added ConfigFolder constant.
mod/primitives/pkg/hex/nibble.go Simplified decodeNibble function by removing redundant conditions and directly checking for character ranges.

Poem

In code's vast expanse, a cleanup spree,
Paths and nibbles, set clutter free.
Refactored paths, elegant and right,
In hexland, nibbles now bright.
With cleaner lines and checks released,
Our Go CLI, a symphony of least. 🌟🐇


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.
    • @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 as 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.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 9a81ca1 and 516262c.

Files selected for processing (2)
  • mod/cli/pkg/commands/jwt/jwt.go (1 hunks)
  • mod/primitives/pkg/hex/nibble.go (1 hunks)
Additional comments not posted (4)
mod/primitives/pkg/hex/nibble.go (3)

31-31: Simplified condition for decoding '0' to '9'.

The changes streamline the condition checks, making the code cleaner and potentially faster by directly comparing the character ranges.


33-33: Simplified condition for decoding 'A' to 'F'.

This adjustment enhances readability and efficiency by focusing directly on the relevant character range.


35-35: Simplified condition for decoding 'a' to 'f'.

Like the previous changes, this modification improves the clarity and directness of the condition, aligning with the PR's goal of removing redundant logic.

mod/cli/pkg/commands/jwt/jwt.go (1)

120-127: Refactored file path retrieval logic.

The removal of the redundant check for an empty specifiedFilePath and the consolidation of the file path assignment process simplify the function and reduce unnecessary branching. This change should make the function more straightforward and maintainable.

Copy link
Contributor

@archbear archbear left a comment

Choose a reason for hiding this comment

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

nit otherwise lgtm

}
specifiedFilePath = filepath.Join(
clientCtx.HomeDir+"/config/", DefaultSecretFileName,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: filepath.Join appends the backslashes correctly according to os spec so hardcoding /config/ isn't necessary if i remember correctly

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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 516262c and 056a0a5.

Files selected for processing (1)
  • mod/cli/pkg/commands/jwt/jwt.go (2 hunks)
Additional comments not posted (2)
mod/cli/pkg/commands/jwt/jwt.go (2)

38-38: Introduction of ConfigFolder constant:

The addition of the ConfigFolder constant enhances modularity by centralizing the configuration directory path. This change supports the PR's objective of simplifying and streamlining code.


121-128: Refactored default file path logic in getFilePath:

The refactoring of the default file path logic to use clientCtx.HomeDir combined with the new ConfigFolder constant is a good improvement. It simplifies the path construction and makes the function more readable and maintainable.

@@ -28,11 +28,11 @@ import (
func decodeNibble(in byte) uint64 {
// uint64 conversion here is safe
switch {
case in >= '0' && in <= '9' && in >= hexBaseOffset:
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hexBaseOffset is already '0' so no need for comparison here. Same with the other if statements

Copy link
Contributor

Choose a reason for hiding this comment

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

you're right. wanna add a brief comment clarifying that this would never underflow?

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe above each return, add a comment containing the expected range of the result.

ex. in - hexBaseOffset would result in a value in 0-9, in - hexAlphaOffsetUpper would result in a value in 10-15, etc.

@@ -117,16 +118,14 @@ func getFilePath(cmd *cobra.Command, path string) (string, error) {
// If no path is specified, try to get the cosmos client context and use
// the configured home directory to write the secret to the default file
// name.
if specifiedFilePath == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think this is logically equivalent

Copy link
Contributor

Choose a reason for hiding this comment

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

is it not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we already early return if specifiedFilePath is not empty here so no need to check again.

Copy link
Contributor

@itsdevbear itsdevbear left a comment

Choose a reason for hiding this comment

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

yup I agree with all points,

@TropicalDog17 just add a comment for what ocnc2 and i'm good to merge

Copy link
Contributor

@ocnc2 ocnc2 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 @TropicalDog17!

@itsdevbear itsdevbear merged commit b8ac860 into berachain:main Jun 23, 2024
14 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.

4 participants