Skip to content

Commit

Permalink
refactor: simplify with strings.Prefix, strings.CutPrefix (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Nov 19, 2024
1 parent 93c6bc8 commit 1425e2f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
5 changes: 1 addition & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ func getVersion(builtBy, date, commit, version string) string {
if version == defaultVersion {
bi, ok := debug.ReadBuildInfo()
if ok {
version = bi.Main.Version
if strings.HasPrefix(version, "v") {
version = strings.TrimLeft(bi.Main.Version, "v")
}
version = strings.TrimPrefix(bi.Main.Version, "v")
if len(buildInfo) == 0 {
return fmt.Sprintf("version %s\n", version)
}
Expand Down
4 changes: 2 additions & 2 deletions rule/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) {
if t.Name.Name == a {
continue
}
if strings.HasPrefix(s, a+" ") {
s = s[len(a)+1:]
var found bool
if s, found = strings.CutPrefix(s, a+" "); found {
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions rule/struct_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string {
switch tag.Key {
case keyProtobuf:
for _, option := range tag.Options {
if strings.HasPrefix(option, "name=") {
return strings.TrimPrefix(option, "name=")
if tagName, found := strings.CutPrefix(option, "name="); found {
return tagName
}
}
return "" // protobuf tag lacks 'name' option
Expand Down

0 comments on commit 1425e2f

Please sign in to comment.