mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
refactor: simplify with strings.Prefix, strings.CutPrefix (#1137)
This commit is contained in:
@@ -189,10 +189,7 @@ func getVersion(builtBy, date, commit, version string) string {
|
|||||||
if version == defaultVersion {
|
if version == defaultVersion {
|
||||||
bi, ok := debug.ReadBuildInfo()
|
bi, ok := debug.ReadBuildInfo()
|
||||||
if ok {
|
if ok {
|
||||||
version = bi.Main.Version
|
version = strings.TrimPrefix(bi.Main.Version, "v")
|
||||||
if strings.HasPrefix(version, "v") {
|
|
||||||
version = strings.TrimLeft(bi.Main.Version, "v")
|
|
||||||
}
|
|
||||||
if len(buildInfo) == 0 {
|
if len(buildInfo) == 0 {
|
||||||
return fmt.Sprintf("version %s\n", version)
|
return fmt.Sprintf("version %s\n", version)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,8 +252,8 @@ func (w *lintExported) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) {
|
|||||||
if t.Name.Name == a {
|
if t.Name.Name == a {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(s, a+" ") {
|
var found bool
|
||||||
s = s[len(a)+1:]
|
if s, found = strings.CutPrefix(s, a+" "); found {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ func (lintStructTagRule) getTagName(tag *structtag.Tag) string {
|
|||||||
switch tag.Key {
|
switch tag.Key {
|
||||||
case keyProtobuf:
|
case keyProtobuf:
|
||||||
for _, option := range tag.Options {
|
for _, option := range tag.Options {
|
||||||
if strings.HasPrefix(option, "name=") {
|
if tagName, found := strings.CutPrefix(option, "name="); found {
|
||||||
return strings.TrimPrefix(option, "name=")
|
return tagName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "" // protobuf tag lacks 'name' option
|
return "" // protobuf tag lacks 'name' option
|
||||||
|
|||||||
Reference in New Issue
Block a user