diff --git a/semantic/version-alpine.go b/semantic/version-alpine.go index 3f9ea12b..93019636 100644 --- a/semantic/version-alpine.go +++ b/semantic/version-alpine.go @@ -61,7 +61,7 @@ func weightAlpineSuffixString(suffixStr string) int { return len(supported) } -// AlpineVersion represents a version of an Alpine package. +// alpineVersion represents a version of an Alpine package. // // Currently, the APK version specification is as follows: // *number{.number}...{letter}{\_suffix{number}}...{~hash}{-r#}* @@ -81,7 +81,7 @@ func weightAlpineSuffixString(suffixStr string) int { // Finally, an optional package build component *-r{number}* can follow. // // Also see https://github.com/alpinelinux/apk-tools/blob/master/doc/apk-package.5.scd#package-info-metadata -type AlpineVersion struct { +type alpineVersion struct { // the original string that was parsed original string // whether the version was found to be invalid while parsing @@ -103,7 +103,7 @@ type AlpineVersion struct { buildComponent *big.Int } -func (v AlpineVersion) compareComponents(w AlpineVersion) int { +func (v alpineVersion) compareComponents(w alpineVersion) int { numberOfComponents := max(len(v.components), len(w.components)) for i := range numberOfComponents { @@ -117,7 +117,7 @@ func (v AlpineVersion) compareComponents(w AlpineVersion) int { return 0 } -func (v AlpineVersion) compareLetters(w AlpineVersion) int { +func (v alpineVersion) compareLetters(w alpineVersion) int { if v.letter == "" && w.letter != "" { return -1 } @@ -128,7 +128,7 @@ func (v AlpineVersion) compareLetters(w AlpineVersion) int { return strings.Compare(v.letter, w.letter) } -func (v AlpineVersion) fetchSuffix(n int) alpineSuffix { +func (v alpineVersion) fetchSuffix(n int) alpineSuffix { if len(v.suffixes) <= n { return alpineSuffix{number: big.NewInt(0), weight: 5} } @@ -147,7 +147,7 @@ func (as alpineSuffix) Cmp(bs alpineSuffix) int { return as.number.Cmp(bs.number) } -func (v AlpineVersion) compareSuffixes(w AlpineVersion) int { +func (v alpineVersion) compareSuffixes(w alpineVersion) int { numberOfSuffixes := max(len(v.suffixes), len(w.suffixes)) for i := range numberOfSuffixes { @@ -161,7 +161,7 @@ func (v AlpineVersion) compareSuffixes(w AlpineVersion) int { return 0 } -func (v AlpineVersion) compareBuildComponents(w AlpineVersion) int { +func (v alpineVersion) compareBuildComponents(w alpineVersion) int { if v.buildComponent != nil && w.buildComponent != nil { if diff := v.buildComponent.Cmp(w.buildComponent); diff != 0 { return diff @@ -171,7 +171,7 @@ func (v AlpineVersion) compareBuildComponents(w AlpineVersion) int { return 0 } -func (v AlpineVersion) compareRemainder(w AlpineVersion) int { +func (v alpineVersion) compareRemainder(w alpineVersion) int { if v.remainder == "" && w.remainder != "" { return +1 } @@ -183,7 +183,7 @@ func (v AlpineVersion) compareRemainder(w AlpineVersion) int { return 0 } -func (v AlpineVersion) Compare(w AlpineVersion) int { +func (v alpineVersion) compare(w alpineVersion) int { // if both versions are invalid, then just use a string compare if v.invalid && w.invalid { return strings.Compare(v.original, w.original) @@ -209,18 +209,18 @@ func (v AlpineVersion) Compare(w AlpineVersion) int { return 0 } -func (v AlpineVersion) CompareStr(str string) int { - return v.Compare(parseAlpineVersion(str)) +func (v alpineVersion) CompareStr(str string) int { + return v.compare(parseAlpineVersion(str)) } -// parseAlpineNumberComponents parses the given string into AlpineVersion.components +// parseAlpineNumberComponents parses the given string into alpineVersion.components // and then returns the remainder of the string for continued parsing. // // Each number component is a sequence of digits (0-9), separated with a ".", // and with no limit on the value or amount of number components. // // This parser must be applied *before* any other parser. -func parseAlpineNumberComponents(v *AlpineVersion, str string) string { +func parseAlpineNumberComponents(v *alpineVersion, str string) string { sub := cachedregexp.MustCompile(`^((\d+)\.?)*`).FindString(str) if sub == "" { @@ -238,14 +238,14 @@ func parseAlpineNumberComponents(v *AlpineVersion, str string) string { return strings.TrimPrefix(str, sub) } -// parseAlpineLetter parses the given string into an AlpineVersion.letter +// parseAlpineLetter parses the given string into an alpineVersion.letter // and then returns the remainder of the string for continued parsing. // // The letter is optional, following after the numeric version components, and // must be a single lower case letter (a-z). // // This parser must be applied *after* parseAlpineNumberComponents. -func parseAlpineLetter(v *AlpineVersion, str string) string { +func parseAlpineLetter(v *alpineVersion, str string) string { if cachedregexp.MustCompile(`^[a-z]`).MatchString(str) { v.letter = str[:1] } @@ -253,13 +253,13 @@ func parseAlpineLetter(v *AlpineVersion, str string) string { return strings.TrimPrefix(str, v.letter) } -// parseAlpineSuffixes parses the given string into AlpineVersion.suffixes and +// parseAlpineSuffixes parses the given string into alpineVersion.suffixes and // then returns the remainder of the string for continued parsing. // // Suffixes begin with an "_" and may optionally end with a number. // // This parser must be applied *after* parseAlpineLetter. -func parseAlpineSuffixes(v *AlpineVersion, str string) string { +func parseAlpineSuffixes(v *alpineVersion, str string) string { re := cachedregexp.MustCompile(`_(alpha|beta|pre|rc|cvs|svn|git|hg|p)(\d*)`) for _, match := range re.FindAllStringSubmatch(str, -1) { @@ -277,7 +277,7 @@ func parseAlpineSuffixes(v *AlpineVersion, str string) string { return str } -// parseAlpineHash parses the given string into AlpineVersion.hash and then returns +// parseAlpineHash parses the given string into alpineVersion.hash and then returns // the remainder of the string for continued parsing. // // The hash is an optional value representing a commit hash, which is a string of @@ -285,7 +285,7 @@ func parseAlpineSuffixes(v *AlpineVersion, str string) string { // digits (0-9a-f). // // This parser must be applied *after* parseAlpineSuffixes. -func parseAlpineHash(v *AlpineVersion, str string) string { +func parseAlpineHash(v *alpineVersion, str string) string { re := cachedregexp.MustCompile(`^~([0-9a-f]+)`) v.hash = re.FindString(str) @@ -293,14 +293,14 @@ func parseAlpineHash(v *AlpineVersion, str string) string { return strings.TrimPrefix(str, v.hash) } -// parseAlpineBuildComponent parses the given string into AlpineVersion.buildComponent +// parseAlpineBuildComponent parses the given string into alpineVersion.buildComponent // and then returns the remainder of the string for continued parsing. // // The build component is an optional value at the end of the version string which // begins with "-r" followed by a number. // // This parser must be applied *after* parseAlpineBuildComponent -func parseAlpineBuildComponent(v *AlpineVersion, str string) string { +func parseAlpineBuildComponent(v *alpineVersion, str string) string { if str == "" { return str } @@ -326,8 +326,8 @@ func parseAlpineBuildComponent(v *AlpineVersion, str string) string { return strings.TrimPrefix(str, matches[0]) } -func parseAlpineVersion(str string) AlpineVersion { - v := AlpineVersion{original: str, buildComponent: new(big.Int)} +func parseAlpineVersion(str string) alpineVersion { + v := alpineVersion{original: str, buildComponent: new(big.Int)} str = parseAlpineNumberComponents(&v, str) str = parseAlpineLetter(&v, str) diff --git a/semantic/version-cran.go b/semantic/version-cran.go index 19fa37c6..2b02e8b3 100644 --- a/semantic/version-cran.go +++ b/semantic/version-cran.go @@ -5,18 +5,18 @@ import ( "strings" ) -// CRANVersion is the representation of a version of a package that is held +// cranVersion is the representation of a version of a package that is held // in the CRAN ecosystem (https://cran.r-project.org/). // // A version is a sequence of at least two non-negative integers separated by // either a period or a dash. // // See https://astrostatistics.psu.edu/su07/R/html/base/html/package_version.html -type CRANVersion struct { - components Components +type cranVersion struct { + components components } -func (v CRANVersion) Compare(w CRANVersion) int { +func (v cranVersion) compare(w cranVersion) int { if diff := v.components.Cmp(w.components); diff != 0 { return diff } @@ -34,15 +34,16 @@ func (v CRANVersion) Compare(w CRANVersion) int { return -1 } -func (v CRANVersion) CompareStr(str string) int { - return v.Compare(parseCRANVersion(str)) +func (v cranVersion) CompareStr(str string) int { + return v.compare(parseCRANVersion(str)) } -func parseCRANVersion(str string) CRANVersion { +func parseCRANVersion(str string) cranVersion { // dashes and periods have the same weight, so we can just normalize to periods parts := strings.Split(strings.ReplaceAll(str, "-", "."), ".") - components := make(Components, 0, len(parts)) + // TODO: refactor to avoid shadowing the components type + components := make(components, 0, len(parts)) for _, s := range parts { v, _ := new(big.Int).SetString(s, 10) @@ -50,5 +51,5 @@ func parseCRANVersion(str string) CRANVersion { components = append(components, v) } - return CRANVersion{components} + return cranVersion{components} } diff --git a/semantic/version-debian.go b/semantic/version-debian.go index df1c7971..bf640ce4 100644 --- a/semantic/version-debian.go +++ b/semantic/version-debian.go @@ -117,13 +117,13 @@ func compareDebianVersions(a, b string) int { return 0 } -type DebianVersion struct { +type debianVersion struct { epoch *big.Int upstream string revision string } -func (v DebianVersion) Compare(w DebianVersion) int { +func (v debianVersion) compare(w debianVersion) int { if diff := v.epoch.Cmp(w.epoch); diff != 0 { return diff } @@ -137,11 +137,11 @@ func (v DebianVersion) Compare(w DebianVersion) int { return 0 } -func (v DebianVersion) CompareStr(str string) int { - return v.Compare(parseDebianVersion(str)) +func (v debianVersion) CompareStr(str string) int { + return v.compare(parseDebianVersion(str)) } -func parseDebianVersion(str string) DebianVersion { +func parseDebianVersion(str string) debianVersion { var upstream, revision string str = strings.TrimSpace(str) @@ -160,5 +160,5 @@ func parseDebianVersion(str string) DebianVersion { revision = "0" } - return DebianVersion{epoch, upstream, revision} + return debianVersion{epoch, upstream, revision} } diff --git a/semantic/version-maven.go b/semantic/version-maven.go index 23edaee2..078f54aa 100644 --- a/semantic/version-maven.go +++ b/semantic/version-maven.go @@ -98,11 +98,11 @@ func (vt *mavenVersionToken) lessThan(wt mavenVersionToken) bool { return vt.qualifierOrder() < wt.qualifierOrder() } -type MavenVersion struct { +type mavenVersion struct { tokens []mavenVersionToken } -func (mv MavenVersion) equal(mw MavenVersion) bool { +func (mv mavenVersion) equal(mw mavenVersion) bool { if len(mv.tokens) != len(mw.tokens) { return false } @@ -135,7 +135,7 @@ func newMavenNullVersionToken(token mavenVersionToken) mavenVersionToken { panic(fmt.Sprintf("unknown prefix '%s' (value: '%s')", token.prefix, token.value)) } -func (mv MavenVersion) lessThan(mw MavenVersion) bool { +func (mv mavenVersion) lessThan(mw mavenVersion) bool { numberOfTokens := max(len(mv.tokens), len(mw.tokens)) var left mavenVersionToken @@ -202,7 +202,7 @@ func splitCharsInclusive(s, chars string) (out []string) { return } -func newMavenVersion(str string) MavenVersion { +func newMavenVersion(str string) mavenVersion { var tokens []mavenVersionToken // The Maven coordinate is split in tokens between dots ('.'), hyphens ('-') @@ -299,9 +299,9 @@ func newMavenVersion(str string) MavenVersion { i-- } - return MavenVersion{tokens} + return mavenVersion{tokens} } -func (mv MavenVersion) Compare(w MavenVersion) int { +func (mv mavenVersion) compare(w mavenVersion) int { if mv.equal(w) { return 0 } @@ -312,10 +312,10 @@ func (mv MavenVersion) Compare(w MavenVersion) int { return +1 } -func (mv MavenVersion) CompareStr(str string) int { - return mv.Compare(parseMavenVersion(str)) +func (mv mavenVersion) CompareStr(str string) int { + return mv.compare(parseMavenVersion(str)) } -func parseMavenVersion(str string) MavenVersion { +func parseMavenVersion(str string) mavenVersion { return newMavenVersion(str) } diff --git a/semantic/version-nuget.go b/semantic/version-nuget.go index 2bda912e..fca6510a 100644 --- a/semantic/version-nuget.go +++ b/semantic/version-nuget.go @@ -2,11 +2,11 @@ package semantic import "strings" -type NuGetVersion struct { - SemverLikeVersion +type nuGetVersion struct { + semverLikeVersion } -func (v NuGetVersion) Compare(w NuGetVersion) int { +func (v nuGetVersion) compare(w nuGetVersion) int { if diff := v.Components.Cmp(w.Components); diff != 0 { return diff } @@ -14,10 +14,10 @@ func (v NuGetVersion) Compare(w NuGetVersion) int { return compareBuildComponents(strings.ToLower(v.Build), strings.ToLower(w.Build)) } -func (v NuGetVersion) CompareStr(str string) int { - return v.Compare(parseNuGetVersion(str)) +func (v nuGetVersion) CompareStr(str string) int { + return v.compare(parseNuGetVersion(str)) } -func parseNuGetVersion(str string) NuGetVersion { - return NuGetVersion{ParseSemverLikeVersion(str, 4)} +func parseNuGetVersion(str string) nuGetVersion { + return nuGetVersion{parseSemverLikeVersion(str, 4)} } diff --git a/semantic/version-packagist.go b/semantic/version-packagist.go index bef19de4..d0eabefd 100644 --- a/semantic/version-packagist.go +++ b/semantic/version-packagist.go @@ -104,22 +104,22 @@ func comparePackagistComponents(a, b []string) int { return 0 } -type PackagistVersion struct { +type packagistVersion struct { Original string Components []string } -func parsePackagistVersion(str string) PackagistVersion { - return PackagistVersion{ +func parsePackagistVersion(str string) packagistVersion { + return packagistVersion{ str, strings.Split(canonicalizePackagistVersion(str), "."), } } -func (v PackagistVersion) Compare(w PackagistVersion) int { +func (v packagistVersion) compare(w packagistVersion) int { return comparePackagistComponents(v.Components, w.Components) } -func (v PackagistVersion) CompareStr(str string) int { - return v.Compare(parsePackagistVersion(str)) +func (v packagistVersion) CompareStr(str string) int { + return v.compare(parsePackagistVersion(str)) } diff --git a/semantic/version-pypi.go b/semantic/version-pypi.go index d016c03c..9c6477ee 100644 --- a/semantic/version-pypi.go +++ b/semantic/version-pypi.go @@ -8,9 +8,9 @@ import ( "github.com/google/osv-scalibr/internal/cachedregexp" ) -type PyPIVersion struct { +type pyPIVersion struct { epoch *big.Int - release Components + release components pre letterAndNumber post letterAndNumber dev letterAndNumber @@ -128,13 +128,13 @@ func parsePyPIVersionParts(str string) (parts []string) { return parts } -func parsePyPILegacyVersion(str string) PyPIVersion { +func parsePyPILegacyVersion(str string) pyPIVersion { parts := parsePyPIVersionParts(str) - return PyPIVersion{epoch: big.NewInt(-1), legacy: parts} + return pyPIVersion{epoch: big.NewInt(-1), legacy: parts} } -func parsePyPIVersion(str string) PyPIVersion { +func parsePyPIVersion(str string) pyPIVersion { str = strings.ToLower(str) // from https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions @@ -145,7 +145,7 @@ func parsePyPIVersion(str string) PyPIVersion { return parsePyPILegacyVersion(str) } - var version PyPIVersion + var version pyPIVersion version.epoch = big.NewInt(0) @@ -173,20 +173,20 @@ func parsePyPIVersion(str string) PyPIVersion { } // Compares the epoch segments of each version -func (pv PyPIVersion) compareEpoch(pw PyPIVersion) int { +func (pv pyPIVersion) compareEpoch(pw pyPIVersion) int { return pv.epoch.Cmp(pw.epoch) } // Compares the release segments of each version, which considers the numeric value // of each component in turn; when comparing release segments with different numbers // of components, the shorter segment is padded out with additional zeros as necessary. -func (pv PyPIVersion) compareRelease(pw PyPIVersion) int { +func (pv pyPIVersion) compareRelease(pw pyPIVersion) int { return pv.release.Cmp(pw.release) } -// Checks if this PyPIVersion should apply a sort trick when comparing pre, +// Checks if this pyPIVersion should apply a sort trick when comparing pre, // which ensures that i.e. 1.0.dev0 is before 1.0a0. -func (pv PyPIVersion) shouldApplyPreTrick() bool { +func (pv pyPIVersion) shouldApplyPreTrick() bool { return pv.pre.number == nil && pv.post.number == nil && pv.dev.number != nil } @@ -197,7 +197,7 @@ func (pv PyPIVersion) shouldApplyPreTrick() bool { // candidate) and then by the numerical component within that phase. // // Versions without a pre-release are sorted after those with one. -func (pv PyPIVersion) comparePre(pw PyPIVersion) int { +func (pv pyPIVersion) comparePre(pw pyPIVersion) int { switch { case pv.shouldApplyPreTrick() && pw.shouldApplyPreTrick(): return +0 @@ -232,7 +232,7 @@ func (pv PyPIVersion) comparePre(pw PyPIVersion) int { // the corresponding release, and ahead of any subsequent release. // // Versions without a post segment are sorted before those with one. -func (pv PyPIVersion) comparePost(pw PyPIVersion) int { +func (pv pyPIVersion) comparePost(pw pyPIVersion) int { switch { case pv.post.number == nil && pw.post.number == nil: return +0 @@ -253,7 +253,7 @@ func (pv PyPIVersion) comparePost(pw PyPIVersion) int { // and following any previous release (including any post-releases). // // Versions without a development segment are sorted after those with one. -func (pv PyPIVersion) compareDev(pw PyPIVersion) int { +func (pv pyPIVersion) compareDev(pw pyPIVersion) int { switch { case pv.dev.number == nil && pw.dev.number == nil: return +0 @@ -267,7 +267,7 @@ func (pv PyPIVersion) compareDev(pw PyPIVersion) int { } // Compares the local segment of each version -func (pv PyPIVersion) compareLocal(pw PyPIVersion) int { +func (pv pyPIVersion) compareLocal(pw pyPIVersion) int { minVersionLength := min(len(pv.local), len(pw.local)) var compare int @@ -319,7 +319,7 @@ func (pv PyPIVersion) compareLocal(pw PyPIVersion) int { // // http://peak.telecommunity.com/DevCenter/setuptools#specifying-your-project-s-version // looks like a good reference, but unsure where it sits in the actual tooling history -func (pv PyPIVersion) compareLegacy(pw PyPIVersion) int { +func (pv pyPIVersion) compareLegacy(pw pyPIVersion) int { if len(pv.legacy) == 0 && len(pw.legacy) == 0 { return +0 } @@ -336,7 +336,7 @@ func (pv PyPIVersion) compareLegacy(pw PyPIVersion) int { ) } -func pypiCompareVersion(v, w PyPIVersion) int { +func pypiCompareVersion(v, w pyPIVersion) int { if legacyDiff := v.compareLegacy(w); legacyDiff != 0 { return legacyDiff } @@ -362,10 +362,10 @@ func pypiCompareVersion(v, w PyPIVersion) int { return 0 } -func (pv PyPIVersion) Compare(pw PyPIVersion) int { +func (pv pyPIVersion) compare(pw pyPIVersion) int { return pypiCompareVersion(pv, pw) } -func (pv PyPIVersion) CompareStr(str string) int { - return pv.Compare(parsePyPIVersion(str)) +func (pv pyPIVersion) CompareStr(str string) int { + return pv.compare(parsePyPIVersion(str)) } diff --git a/semantic/version-redhat.go b/semantic/version-redhat.go index 49d4a7a2..d46e9aa5 100644 --- a/semantic/version-redhat.go +++ b/semantic/version-redhat.go @@ -4,7 +4,7 @@ import ( "strings" ) -type RedHatVersion struct { +type redHatVersion struct { epoch string version string release string @@ -24,12 +24,12 @@ func isASCIILetter(c rune) bool { return (c >= 65 && c <= 90) || (c >= 97 && c <= 122) } -// shouldBeTrimmed checks if the given rune should be trimmed when parsing RedHatVersion components +// shouldBeTrimmed checks if the given rune should be trimmed when parsing redHatVersion components func shouldBeTrimmed(r rune) bool { return !isASCIILetter(r) && !isASCIIDigit(r) && r != '~' && r != '^' } -// compareRedHatComponents compares two components of a RedHatVersion in the same +// compareRedHatComponents compares two components of a redHatVersion in the same // manner as rpmvercmp(8) does. func compareRedHatComponents(a, b string) int { if a == "" && b != "" { @@ -154,7 +154,7 @@ func compareRedHatComponents(a, b string) int { } } - // 10. Compare the leading segments with strcmp() (or <=> in Ruby). If that returns a non-zero value, then return that value. Else continue to the next iteration of the loop. + // 10. compare the leading segments with strcmp() (or <=> in Ruby). If that returns a non-zero value, then return that value. Else continue to the next iteration of the loop. if diff := strings.Compare(as, bs); diff != 0 { return diff } @@ -174,7 +174,7 @@ func compareRedHatComponents(a, b string) int { return 0 } -func (v RedHatVersion) CompareStr(str string) int { +func (v redHatVersion) CompareStr(str string) int { w := parseRedHatVersion(str) if diff := compareRedHatComponents(v.epoch, w.epoch); diff != 0 { @@ -190,7 +190,7 @@ func (v RedHatVersion) CompareStr(str string) int { return 0 } -// parseRedHatVersion parses a Red Hat version into a RedHatVersion struct. +// parseRedHatVersion parses a Red Hat version into a redHatVersion struct. // // A Red Hat version contains the following components: // - name (of the package), represented as "n" @@ -201,7 +201,7 @@ func (v RedHatVersion) CompareStr(str string) int { // // When all components are present, the version is represented as "n-e:v-r.a", // though only the version is actually required. -func parseRedHatVersion(str string) RedHatVersion { +func parseRedHatVersion(str string) redHatVersion { bf, af, hasColon := strings.Cut(str, ":") if !hasColon { @@ -225,5 +225,5 @@ func parseRedHatVersion(str string) RedHatVersion { epoch = "0" } - return RedHatVersion{epoch, version, release} + return redHatVersion{epoch, version, release} } diff --git a/semantic/version-rubygems.go b/semantic/version-rubygems.go index 2904d211..8327ecbb 100644 --- a/semantic/version-rubygems.go +++ b/semantic/version-rubygems.go @@ -100,22 +100,22 @@ func compareRubyGemsComponents(a, b []string) int { return 0 } -type RubyGemsVersion struct { +type rubyGemsVersion struct { Original string Segments []string } -func parseRubyGemsVersion(str string) RubyGemsVersion { - return RubyGemsVersion{ +func parseRubyGemsVersion(str string) rubyGemsVersion { + return rubyGemsVersion{ str, canonicalSegments(strings.Split(canonicalizeRubyGemVersion(str), ".")), } } -func (v RubyGemsVersion) Compare(w RubyGemsVersion) int { +func (v rubyGemsVersion) compare(w rubyGemsVersion) int { return compareRubyGemsComponents(v.Segments, w.Segments) } -func (v RubyGemsVersion) CompareStr(str string) int { - return v.Compare(parseRubyGemsVersion(str)) +func (v rubyGemsVersion) CompareStr(str string) int { + return v.compare(parseRubyGemsVersion(str)) } diff --git a/semantic/version-semver-like.go b/semantic/version-semver-like.go index 29216d16..dc3b6d52 100644 --- a/semantic/version-semver-like.go +++ b/semantic/version-semver-like.go @@ -8,17 +8,17 @@ import ( "github.com/google/osv-scalibr/internal/cachedregexp" ) -// SemverLikeVersion is a version that is _like_ a version as defined by the +// semverLikeVersion is a version that is _like_ a version as defined by the // Semantic Version specification, except with potentially unlimited numeric // components and a leading "v" -type SemverLikeVersion struct { +type semverLikeVersion struct { LeadingV bool - Components Components + Components components Build string Original string } -func (v *SemverLikeVersion) fetchComponentsAndBuild(maxComponents int) (Components, string) { +func (v *semverLikeVersion) fetchComponentsAndBuild(maxComponents int) (components, string) { if len(v.Components) <= maxComponents { return v.Components, v.Build } @@ -35,12 +35,13 @@ func (v *SemverLikeVersion) fetchComponentsAndBuild(maxComponents int) (Componen return comps, build } -func ParseSemverLikeVersion(line string, maxComponents int) SemverLikeVersion { +func parseSemverLikeVersion(line string, maxComponents int) semverLikeVersion { v := parseSemverLike(line) + // TODO: refactor to avoid shadowing the components type components, build := v.fetchComponentsAndBuild(maxComponents) - return SemverLikeVersion{ + return semverLikeVersion{ LeadingV: v.LeadingV, Components: components, Build: build, @@ -48,7 +49,8 @@ func ParseSemverLikeVersion(line string, maxComponents int) SemverLikeVersion { } } -func parseSemverLike(line string) SemverLikeVersion { +func parseSemverLike(line string) semverLikeVersion { + // TODO: refactor to avoid shadowing the components type var components []*big.Int originStr := line @@ -111,7 +113,7 @@ func parseSemverLike(line string) SemverLikeVersion { currentCom = "" } - return SemverLikeVersion{ + return semverLikeVersion{ LeadingV: leadingV, Components: components, Build: currentCom, diff --git a/semantic/version-semver.go b/semantic/version-semver.go index 31307b81..47759d83 100644 --- a/semantic/version-semver.go +++ b/semantic/version-semver.go @@ -82,15 +82,15 @@ func compareSemverBuildComponents(a, b []string) int { return 0 } -type SemverVersion struct { - SemverLikeVersion +type semverVersion struct { + semverLikeVersion } -func parseSemverVersion(str string) SemverVersion { - return SemverVersion{ParseSemverLikeVersion(str, 3)} +func parseSemverVersion(str string) semverVersion { + return semverVersion{parseSemverLikeVersion(str, 3)} } -func (v SemverVersion) Compare(w SemverVersion) int { +func (v semverVersion) compare(w semverVersion) int { if diff := v.Components.Cmp(w.Components); diff != 0 { return diff } @@ -98,6 +98,6 @@ func (v SemverVersion) Compare(w SemverVersion) int { return compareBuildComponents(v.Build, w.Build) } -func (v SemverVersion) CompareStr(str string) int { - return v.Compare(parseSemverVersion(str)) +func (v semverVersion) CompareStr(str string) int { + return v.compare(parseSemverVersion(str)) } diff --git a/semantic/version.go b/semantic/version.go index fdcaeab1..4f9e0633 100644 --- a/semantic/version.go +++ b/semantic/version.go @@ -12,9 +12,9 @@ type Version interface { CompareStr(str string) int } -type Components []*big.Int +type components []*big.Int -func (components *Components) Fetch(n int) *big.Int { +func (components *components) Fetch(n int) *big.Int { if len(*components) <= n { return big.NewInt(0) } @@ -22,7 +22,7 @@ func (components *Components) Fetch(n int) *big.Int { return (*components)[n] } -func (components *Components) Cmp(b Components) int { +func (components *components) Cmp(b components) int { numberOfComponents := max(len(*components), len(b)) for i := range numberOfComponents {