From 674b62d62a1b825973c59213384986a653548d54 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 1 Nov 2024 08:50:55 +1300 Subject: [PATCH] refactor(semantic): remove unneeded logic in parsing semver-like versions (#277) --- pkg/semantic/version-semver-like.go | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/pkg/semantic/version-semver-like.go b/pkg/semantic/version-semver-like.go index 298c2d2c..95ab7ccb 100644 --- a/pkg/semantic/version-semver-like.go +++ b/pkg/semantic/version-semver-like.go @@ -38,10 +38,6 @@ func (v *SemverLikeVersion) fetchComponentsAndBuild(maxComponents int) (Componen func ParseSemverLikeVersion(line string, maxComponents int) SemverLikeVersion { v := parseSemverLike(line) - if maxComponents == -1 { - return v - } - components, build := v.fetchComponentsAndBuild(maxComponents) return SemverLikeVersion{ @@ -60,7 +56,6 @@ func parseSemverLike(line string) SemverLikeVersion { currentCom := "" foundBuild := false - emptyComponent := false leadingV := strings.HasPrefix(line, "v") line = strings.TrimPrefix(line, "v") @@ -94,15 +89,11 @@ func parseSemverLike(line string) SemverLikeVersion { components = append(components, v) currentCom = "" - - emptyComponent = false } // a component terminator means there might be another component // afterwards, so don't start parsing the build string just yet if c == '.' { - emptyComponent = true - continue } @@ -118,19 +109,6 @@ func parseSemverLike(line string) SemverLikeVersion { components = append(components, v) currentCom = "" - emptyComponent = false - } - - // if we ended with an empty component section, - // prefix the build string with a '.' - if emptyComponent { - currentCom = "." + currentCom - } - - // if we found no components, then the v wasn't actually leading - if len(components) == 0 && leadingV { - leadingV = false - currentCom = "v" + currentCom } return SemverLikeVersion{