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: unslice slice expressions #2982

Closed
wants to merge 1 commit into from
Closed

Conversation

estensen
Copy link
Contributor

@estensen estensen commented Jan 4, 2024

Found with gocritic ran with golangci-lint run -E gocritic

Copy link
Contributor

coderabbitai bot commented Jan 4, 2024

Walkthrough

Walkthrough

The recent modifications involve streamlining slice operations in Go. Specifically, the redundant slice expressions have been eliminated when copying and comparing byte slices. This simplification impacts how elements are copied between slices and how byte slices are compared, ensuring a more concise and potentially more efficient implementation.

Changes

File Change Summary
pkg/square/square.go Removed unnecessary slice expressions in copy function call.
.../blobstream/types/validator.go Simplified byte slice comparison in EVMAddrLessThan function by removing redundant slicing.

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's AI:

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.
    • @coderabbitai read the files in the src/scheduler package and generate 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 4, 2024 20:50
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 your interest in improving our codebase! When I run gocritic, I see a few other issues. Is there any reason in particular you choose to focus on the unslice ones?

Also, if we want to avoid regressions, I propose we add gocritic to the list of linters in .golanci.yml.

$ golangci-lint run -E gocritic
pkg/da/data_availability_header.go:213:3: assignOp: replace `result = result << 1` with `result <<= 1` (gocritic)
		result = result << 1
		^
pkg/inclusion/commitment.go:43:3: assignOp: replace `cursor = cursor + treeSize` with `cursor += treeSize` (gocritic)
		cursor = cursor + treeSize
		^
pkg/inclusion/commitment.go:102:4: assignOp: replace `totalSize = totalSize - maxTreeSize` with `totalSize -= maxTreeSize` (gocritic)
			totalSize = totalSize - maxTreeSize
			^
pkg/inclusion/commitment.go:109:4: assignOp: replace `totalSize = totalSize - treeSize` with `totalSize -= treeSize` (gocritic)
			totalSize = totalSize - treeSize
			^
pkg/inclusion/paths.go:166:4: assignOp: replace `leafCursor = leafCursor + nodeRangeCursor` with `leafCursor += nodeRangeCursor` (gocritic)
			leafCursor = leafCursor + nodeRangeCursor
			^
pkg/inclusion/paths.go:167:4: assignOp: replace `nodeRangeCursor = nodeRangeCursor * 2` with `nodeRangeCursor *= 2` (gocritic)
			nodeRangeCursor = nodeRangeCursor * 2
			^
pkg/inclusion/nmt_caching_test.go:147:3: assignOp: replace `subLeafRange = subLeafRange / 2` with `subLeafRange /= 2` (gocritic)
		subLeafRange = subLeafRange / 2
		^
pkg/inclusion/paths_test.go:477:4: assignOp: replace `s = s + "l"` with `s += "l"` (gocritic)
			s = s + "l"
			^
pkg/inclusion/paths_test.go:479:4: assignOp: replace `s = s + "r"` with `s += "r"` (gocritic)
			s = s + "r"
			^
pkg/shares/powers_of_two.go:13:3: assignOp: replace `result = result << 1` with `result <<= 1` (gocritic)
		result = result << 1
		^
pkg/shares/share_builder.go:178:2: assignOp: replace `b.rawShareData[infoByteIndex] = b.rawShareData[infoByteIndex] ^ 0x01` with `b.rawShareData[infoByteIndex] ^= 0x01` (gocritic)
	b.rawShareData[infoByteIndex] = b.rawShareData[infoByteIndex] ^ 0x01
	^
pkg/shares/shares_test.go:21:16: appendAssign: append result not assigned to the same slice (gocritic)
	firstShare := append(sparseNamespaceID,
	              ^
pkg/shares/shares_test.go:27:32: appendAssign: append result not assigned to the same slice (gocritic)
	firstShareWithLongSequence := append(sparseNamespaceID,
	                              ^
pkg/shares/shares_test.go:32:23: appendAssign: append result not assigned to the same slice (gocritic)
	continuationShare := append(sparseNamespaceID,
	                     ^
x/blobstream/types/validator.go:98:23: unslice: could simplify []byte(e.Hex())[:] to []byte(e.Hex()) (gocritic)
	return bytes.Compare([]byte(e.Hex())[:], []byte(o.Hex())[:]) == -1
	                     ^
pkg/square/square.go:265:7: unslice: could simplify square[:] to square (gocritic)
	copy(square[:], txShares)
	     ^
x/upgrade/keeper.go:33:2: singleCaseSwitch: found switch with default case only (gocritic)
	switch version {
	^
x/blob/client/testutil/integration_test.go:177:5: singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
				switch e.Type {
				^

@estensen
Copy link
Contributor Author

estensen commented Jan 5, 2024

@rootulp I'm more than happy to add gocritic and fix all the linters you listed. I just thought it was easier to review multiple tiny PRs.

Also, it's up to you if you agree with all the issues the linter found.

@rootulp
Copy link
Collaborator

rootulp commented Jan 5, 2024

Yea I generally agree, smaller PRs are easier to review. However, in this case there's nothing stopping a subsequent PR from reverting the modifications you make in this PR. IMO if we're going to enable the gocritic linter (which I'm not strongly opinionated on for/against) then I'd rather we enable it in the config so that it runs in CI and subsequent PRs can't introduce any regressions. Does that make sense?

Before we proceed with this line of work, it may be worthwhile to create a GH issue with a short description on gocritic so that we can get alignment from the team on whether it's something we should enable. Our team is generally in favor of linters that reduce the # of nits on PRs and enforce more codebase consistency so gocritic seems like something we should consider.

@estensen
Copy link
Contributor Author

estensen commented Jan 7, 2024

Got it! Created #2987

@rootulp rootulp marked this pull request as draft January 7, 2024 22:39
@rootulp
Copy link
Collaborator

rootulp commented Jan 7, 2024

Converted this to draft b/c if possible, I think it's preferable to fix all the go-critic violations in the same PR that enables the linter in golangci.yml.

@rootulp
Copy link
Collaborator

rootulp commented Jan 21, 2024

Closing because stale. We have another PR that does something similar: #3000 and enables the linter in golangci.yml so thanks for the idea and creating the issue!

@rootulp rootulp closed this Jan 21, 2024
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.

2 participants