Skip to content

Commit c0142c1

Browse files
committed
Go: Add comment explaining why NewSemVer does not Canonicalise the result
1 parent f830dc6 commit c0142c1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

go/extractor/util/semver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func Zero() SemVer {
5353
// versions are also automatically corrected from e.g. "go1.20rc1" to "v1.20-rc1". If given
5454
// the empty string, this function return `nil`. Otherwise, for invalid version strings, the function
5555
// prints a message to the log and exits the process.
56+
//
57+
// Note that we deliberately do not format the resulting [SemVer] to be in a `Canonical` representation.
58+
// This is because we want to maintain the input version specificity for as long as possible. This is useful
59+
// for e.g. `IdentifyEnvironment` where we want to output "1.22" if the project specifies "1.22" as the
60+
// required Go version, rather than outputting "1.22.0", which implies a specific patch-level version
61+
// when the intention is that any patch-level version of "1.22" is acceptable.
5662
func NewSemVer(version string) SemVer {
5763
// If the input is the empty string, return `nil` since we use `nil` to represent "no version".
5864
if version == "" {

0 commit comments

Comments
 (0)