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

fix: replace strings.TrimLeft with strings.TrimPrefix #239

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

Conversation

knbr13
Copy link
Contributor

@knbr13 knbr13 commented Jan 6, 2025

strings.TrimLeft: TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
To remove a prefix, use [TrimPrefix] instead.

example:

s := "hello, world!"
s1 := strings.TrimLeft(s, "olhe,") // s1 = " world!"
s2 := strings.TrimPrefix(s, "hello,") // s2 = " world!"

in the original code, both of them work fine, but the intention of the original code is clearly to remove a prefix rather than all leading Unicode code points contained in cutset, using strings.TrimPrefix clarifies the writer's intention and adheres to the standard library's recommendation.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 6, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants