Skip to content

refactor: use slices.Contains to simplify code #69

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yingshanghuangqiao
Copy link

@yingshanghuangqiao yingshanghuangqiao commented Jun 20, 2025

πŸ“ Summary

There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.

β›± Motivation and Context

πŸ“š References


βœ… I have run these commands

  • make lint
  • make test
  • go mod tidy

@metachris
Copy link
Contributor

thanks!

@metachris metachris requested a review from Copilot June 24, 2025 12:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the HasSource method in TxSummaryEntry to use the new slices.Contains utility from Go 1.21, reducing custom loop logic and improving readability.

  • Replaced manual iteration in HasSource with slices.Contains
  • Added import for the standard-library slices package
  • Simplified code and eliminated boilerplate
Comments suppressed due to low confidence (2)

common/txsummary.go:72

  • [nitpick] Consider adding or updating unit tests for HasSource to cover both matching and non-matching cases now that the implementation has changed.
	return slices.Contains(t.Sources, src)

common/txsummary.go:7

  • Since slices.Contains requires Go 1.21 or later, ensure your go.mod specifies a minimum Go version of 1.21 to avoid build issues.
	"slices"

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