Repository: G-Rath/osv-detector
Pull request #64 (2022-03-12 22:39:35)

refactor: rename `semver` package to `semantic`
Go package naming style says don't use the name of a built-in module, and `semantic` happens to be the same length as the other internal packages so is pleasing :joy:


Patch:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index c978eb7..04332f4 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -13,6 +13,7 @@ builds:
     flags:
       - -trimpath
     ldflags:
+      # prettier-ignore
       - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}}'
     goos:
       - freebsd
diff --git a/detector/database/osv.go b/detector/database/osv.go
index 25ada09..3fcd152 100644
--- a/detector/database/osv.go
+++ b/detector/database/osv.go
@@ -5,7 +5,7 @@ import (
 	"os"
 	"osv-detector/detector"
 	"osv-detector/detector/lockfile"
-	"osv-detector/detector/semver"
+	"osv-detector/detector/semantic"
 	"regexp"
 	"strings"
 	"time"
@@ -65,7 +65,7 @@ func (ar AffectsRange) containsVersion(v string) bool {
 		return false
 	}
 
-	vp := semver.Parse(v)
+	vp := semantic.Parse(v)
 
 	var affected bool
 	for _, e := range ar.Events {
diff --git a/detector/semver/compare.go b/detector/semantic/compare.go
similarity index 99%
rename from detector/semver/compare.go
rename to detector/semantic/compare.go
index 0fab5d0..519e6e3 100644
--- a/detector/semver/compare.go
+++ b/detector/semantic/compare.go
@@ -1,4 +1,4 @@
-package semver
+package semantic
 
 import (
 	"regexp"
diff --git a/detector/semver/fixtures/all-versions.txt b/detector/semantic/fixtures/all-versions.txt
similarity index 100%
rename from detector/semver/fixtures/all-versions.txt
rename to detector/semantic/fixtures/all-versions.txt
diff --git a/detector/semver/parse.go b/detector/semantic/parse.go
similarity index 99%
rename from detector/semver/parse.go
rename to detector/semantic/parse.go
index 37ff549..ddd2424 100644
--- a/detector/semver/parse.go
+++ b/detector/semantic/parse.go
@@ -1,4 +1,4 @@
-package semver
+package semantic
 
 import (
 	"regexp"
diff --git a/detector/semver/version.go b/detector/semantic/version.go
similarity index 96%
rename from detector/semver/version.go
rename to detector/semantic/version.go
index 37c46c8..42baa2b 100644
--- a/detector/semver/version.go
+++ b/detector/semantic/version.go
@@ -1,4 +1,4 @@
-package semver
+package semantic
 
 import (
 	"fmt"


Test patch:
diff --git a/detector/semver/compare_test.go b/detector/semantic/compare_test.go
similarity index 96%
rename from detector/semver/compare_test.go
rename to detector/semantic/compare_test.go
index 780395f..8426307 100644
--- a/detector/semver/compare_test.go
+++ b/detector/semantic/compare_test.go
@@ -1,7 +1,7 @@
-package semver_test
+package semantic_test
 
 import (
-	"osv-detector/detector/semver"
+	"osv-detector/detector/semantic"
 	"testing"
 )
 
@@ -24,8 +24,8 @@ func compareWord(t *testing.T, result int) string {
 
 func expectCompareResult(
 	t *testing.T,
-	a semver.Version,
-	b semver.Version,
+	a semantic.Version,
+	b semantic.Version,
 	expectedResult int,
 ) {
 	t.Helper()
@@ -41,8 +41,8 @@ func expectCompareResult(
 	}
 }
 
-func buildlessVersion(build string, components ...int) semver.Version {
-	return semver.Version{Components: components, Build: build}
+func buildlessVersion(build string, components ...int) semantic.Version {
+	return semantic.Version{Components: components, Build: build}
 }
 
 func TestVersion_Compare_BasicEqual(t *testing.T) {
diff --git a/detector/semver/parse_test.go b/detector/semantic/parse_test.go
similarity index 70%
rename from detector/semver/parse_test.go
rename to detector/semantic/parse_test.go
index 87d738a..2b8c0ea 100644
--- a/detector/semver/parse_test.go
+++ b/detector/semantic/parse_test.go
@@ -1,15 +1,15 @@
-package semver_test
+package semantic_test
 
 import (
 	"bufio"
 	"fmt"
 	"os"
-	"osv-detector/detector/semver"
+	"osv-detector/detector/semantic"
 	"strings"
 	"testing"
 )
 
-func versionsEqual(expectedVersion semver.Version, actualVersion semver.Version) bool {
+func versionsEqual(expectedVersion semantic.Version, actualVersion semantic.Version) bool {
 	if expectedVersion.Build != actualVersion.Build {
 		return false
 	}
@@ -27,7 +27,7 @@ func versionsEqual(expectedVersion semver.Version, actualVersion semver.Version)
 	return true
 }
 
-func explainVersion(version semver.Version) string {
+func explainVersion(version semantic.Version) string {
 	str := "{ "
 
 	for i, component := range version.Components {
@@ -40,7 +40,7 @@ func explainVersion(version semver.Version) string {
 	return str
 }
 
-func notExpectedMessage(version string, expectedVersion semver.Version, actualVersion semver.Version) string {
+func notExpectedMessage(version string, expectedVersion semantic.Version, actualVersion semantic.Version) string {
 	str := fmt.Sprintf("'%s' was not parsed as expected:", version)
 
 	str += fmt.Sprintf("\n  Expected: %s", explainVersion(expectedVersion))
@@ -49,10 +49,10 @@ func notExpectedMessage(version string, expectedVersion semver.Version, actualVe
 	return str
 }
 
-func expectParsedVersionToMatchOriginalString(t *testing.T, str string) semver.Version {
+func expectParsedVersionToMatchOriginalString(t *testing.T, str string) semantic.Version {
 	t.Helper()
 
-	actualVersion := semver.Parse(str)
+	actualVersion := semantic.Parse(str)
 
 	if actualVersion.ToString() != str {
 		t.Errorf(
@@ -65,7 +65,7 @@ func expectParsedVersionToMatchOriginalString(t *testing.T, str string) semver.V
 	return actualVersion
 }
 
-func expectParsedAsVersion(t *testing.T, str string, expectedVersion semver.Version) {
+func expectParsedAsVersion(t *testing.T, str string, expectedVersion semantic.Version) {
 	t.Helper()
 
 	actualVersion := expectParsedVersionToMatchOriginalString(t, str)
@@ -79,11 +79,11 @@ func expectParsedVersionToMatchString(
 	t *testing.T,
 	str string,
 	expectedString string,
-	expectedVersion semver.Version,
+	expectedVersion semantic.Version,
 ) {
 	t.Helper()
 
-	actualVersion := semver.Parse(str)
+	actualVersion := semantic.Parse(str)
 
 	if actualVersion.ToString() != expectedString {
 		t.Errorf(
@@ -101,37 +101,37 @@ func expectParsedVersionToMatchString(
 func TestParse_Standard(t *testing.T) {
 	t.Parallel()
 
-	expectParsedAsVersion(t, "0.0.0.0", semver.Version{
+	expectParsedAsVersion(t, "0.0.0.0", semantic.Version{
 		Components: []int{0, 0, 0, 0},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.0.0.0", semver.Version{
+	expectParsedAsVersion(t, "1.0.0.0", semantic.Version{
 		Components: []int{1, 0, 0, 0},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2.0.0", semver.Version{
+	expectParsedAsVersion(t, "1.2.0.0", semantic.Version{
 		Components: []int{1, 2, 0, 0},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2.3.0", semver.Version{
+	expectParsedAsVersion(t, "1.2.3.0", semantic.Version{
 		Components: []int{1, 2, 3, 0},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2.3.4", semver.Version{
+	expectParsedAsVersion(t, "1.2.3.4", semantic.Version{
 		Components: []int{1, 2, 3, 4},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "9.2.55826.0", semver.Version{
+	expectParsedAsVersion(t, "9.2.55826.0", semantic.Version{
 		Components: []int{9, 2, 55826, 0},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "3.2.22.3", semver.Version{
+	expectParsedAsVersion(t, "3.2.22.3", semantic.Version{
 		Components: []int{3, 2, 22, 3},
 		Build:      "",
 	})
@@ -140,22 +140,22 @@ func TestParse_Standard(t *testing.T) {
 func TestParse_Omitted(t *testing.T) {
 	t.Parallel()
 
-	expectParsedAsVersion(t, "1", semver.Version{
+	expectParsedAsVersion(t, "1", semantic.Version{
 		Components: []int{1},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2", semver.Version{
+	expectParsedAsVersion(t, "1.2", semantic.Version{
 		Components: []int{1, 2},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2.3", semver.Version{
+	expectParsedAsVersion(t, "1.2.3", semantic.Version{
 		Components: []int{1, 2, 3},
 		Build:      "",
 	})
 
-	expectParsedAsVersion(t, "1.2.3.", semver.Version{
+	expectParsedAsVersion(t, "1.2.3.", semantic.Version{
 		Components: []int{1, 2, 3},
 		Build:      ".",
 	})
@@ -164,42 +164,42 @@ func TestParse_Omitted(t *testing.T) {
 func TestParse_WithBuildString(t *testing.T) {
 	t.Parallel()
 
-	expectParsedAsVersion(t, "10.0.0.beta1", semver.Version{
+	expectParsedAsVersion(t, "10.0.0.beta1", semantic.Version{
 		Components: []int{10, 0, 0},
 		Build:      ".beta1",
 	})
 
-	expectParsedAsVersion(t, "1.0.0a20", semver.Version{
+	expectParsedAsVersion(t, "1.0.0a20", semantic.Version{
 		Components: []int{1, 0, 0},
 		Build:      "a20",
 	})
 
-	expectParsedAsVersion(t, "9.0.0.pre1", semver.Version{
+	expectParsedAsVersion(t, "9.0.0.pre1", semantic.Version{
 		Components: []int{9, 0, 0},
 		Build:      ".pre1",
 	})
 
-	expectParsedAsVersion(t, "9.4.16.v20190411", semver.Version{
+	expectParsedAsVersion(t, "9.4.16.v20190411", semantic.Version{
 		Components: []int{9, 4, 16},
 		Build:      ".v20190411",
 	})
 
-	expectParsedAsVersion(t, "0.3.0-beta.83", semver.Version{
+	expectParsedAsVersion(t, "0.3.0-beta.83", semantic.Version{
 		Components: []int{0, 3, 0},
 		Build:      "-beta.83",
 	})
 
-	expectParsedAsVersion(t, "3.0.0-beta.17.5", semver.Version{
+	expectParsedAsVersion(t, "3.0.0-beta.17.5", semantic.Version{
 		Components: []int{3, 0, 0},
 		Build:      "-beta.17.5",
 	})
 
-	expectParsedAsVersion(t, "4.0.0-milestone3", semver.Version{
+	expectParsedAsVersion(t, "4.0.0-milestone3", semantic.Version{
 		Components: []int{4, 0, 0},
 		Build:      "-milestone3",
 	})
 
-	expectParsedAsVersion(t, "13.6RC1", semver.Version{
+	expectParsedAsVersion(t, "13.6RC1", semantic.Version{
 		Components: []int{13, 6},
 		Build:      "RC1",
 	})
@@ -242,12 +242,12 @@ func TestParse_NoComponents(t *testing.T) {
 func TestParse_LeadingZerosAndDateLike(t *testing.T) {
 	t.Parallel()
 
-	expectParsedVersionToMatchString(t, "20.04.0", "20.4.0", semver.Version{
+	expectParsedVersionToMatchString(t, "20.04.0", "20.4.0", semantic.Version{
 		Components: []int{20, 4, 0},
 		Build:      "",
 	})
 
-	expectParsedVersionToMatchString(t, "4.3.04", "4.3.4", semver.Version{
+	expectParsedVersionToMatchString(t, "4.3.04", "4.3.4", semantic.Version{
 		Components: []int{4, 3, 4},
 		Build:      "",
 	})
@@ -263,32 +263,32 @@ func TestParse_LeadingZerosAndDateLike(t *testing.T) {
 func TestParse_DateLike(t *testing.T) {
 	t.Parallel()
 
-	expectParsedVersionToMatchString(t, "20.04.0", "20.4.0", semver.Version{
+	expectParsedVersionToMatchString(t, "20.04.0", "20.4.0", semantic.Version{
 		Components: []int{20, 4, 0},
 		Build:      "",
 	})
 
-	expectParsedVersionToMatchString(t, "4.3.04alpha01", "4.3.4alpha01", semver.Version{
+	expectParsedVersionToMatchString(t, "4.3.04alpha01", "4.3.4alpha01", semantic.Version{
 		Components: []int{4, 3, 4},
 		Build:      "alpha01",
 	})
 
-	expectParsedVersionToMatchString(t, "2019.03.6.1", "2019.3.6.1", semver.Version{
+	expectParsedVersionToMatchString(t, "2019.03.6.1", "2019.3.6.1", semantic.Version{
 		Components: []int{2019, 3, 6, 1},
 		Build:      "",
 	})
 
-	expectParsedVersionToMatchString(t, "19.04.15", "19.4.15", semver.Version{
+	expectParsedVersionToMatchString(t, "19.04.15", "19.4.15", semantic.Version{
 		Components: []int{19, 4, 15},
 		Build:      "",
 	})
 
-	expectParsedVersionToMatchString(t, "20.04.13", "20.4.13", semver.Version{
+	expectParsedVersionToMatchString(t, "20.04.13", "20.4.13", semantic.Version{
 		Components: []int{20, 4, 13},
 		Build:      "",
 	})
 
-	expectParsedVersionToMatchString(t, "2019.11.09", "2019.11.9", semver.Version{
+	expectParsedVersionToMatchString(t, "2019.11.09", "2019.11.9", semantic.Version{
 		Components: []int{2019, 11, 9},
 		Build:      "",
 	})