Skip to content

Commit

Permalink
Merge pull request #502 from ackama:semantic/avoid-shadowing
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 732054367
  • Loading branch information
copybara-github committed Feb 28, 2025
2 parents 30e8a92 + 290daeb commit 5926821
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion semantic/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func runAgainstEcosystemFixture(t *testing.T, ecosystem string, filename string)
t.Errorf("%d of %d failed", failed, total)
}

if err := scanner.Err(); err != nil {
if err = scanner.Err(); err != nil {
t.Fatal(err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions semantic/version-cran.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ func parseCRANVersion(str string) (cranVersion, error) {
// dashes and periods have the same weight, so we can just normalize to periods
parts := strings.Split(strings.ReplaceAll(str, "-", "."), ".")

// TODO: refactor to avoid shadowing the components type
components := make(components, 0, len(parts))
comps := make(components, 0, len(parts))

for _, s := range parts {
v, _ := new(big.Int).SetString(s, 10)

components = append(components, v)
comps = append(comps, v)
}

return cranVersion{components}, nil
return cranVersion{comps}, nil
}
4 changes: 2 additions & 2 deletions semantic/version-pypi.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ func parsePyPIVersion(str string) (pyPIVersion, error) {

version.epoch = big.NewInt(0)

if epoch := match[pypiVersionFinder.SubexpIndex("epoch")]; epoch != "" {
epoch, err := convertToBigInt(epoch)
if epStr := match[pypiVersionFinder.SubexpIndex("epoch")]; epStr != "" {
epoch, err := convertToBigInt(epStr)

if err != nil {
return pyPIVersion{}, err
Expand Down
14 changes: 6 additions & 8 deletions semantic/version-semver-like.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,18 @@ func (v *semverLikeVersion) fetchComponentsAndBuild(maxComponents int) (componen
func parseSemverLikeVersion(line string, maxComponents int) semverLikeVersion {
v := parseSemverLike(line)

// TODO: refactor to avoid shadowing the components type
components, build := v.fetchComponentsAndBuild(maxComponents)
comps, build := v.fetchComponentsAndBuild(maxComponents)

return semverLikeVersion{
LeadingV: v.LeadingV,
Components: components,
Components: comps,
Build: build,
Original: v.Original,
}
}

func parseSemverLike(line string) semverLikeVersion {
// TODO: refactor to avoid shadowing the components type
var components []*big.Int
var comps []*big.Int
originStr := line

currentCom := ""
Expand Down Expand Up @@ -104,7 +102,7 @@ func parseSemverLike(line string) semverLikeVersion {
if currentCom != "" {
v, _ := new(big.Int).SetString(currentCom, 10)

components = append(components, v)
comps = append(comps, v)
currentCom = ""
}

Expand All @@ -124,13 +122,13 @@ func parseSemverLike(line string) semverLikeVersion {
if !foundBuild && currentCom != "" {
v, _ := new(big.Int).SetString(currentCom, 10)

components = append(components, v)
comps = append(comps, v)
currentCom = ""
}

return semverLikeVersion{
LeadingV: leadingV,
Components: components,
Components: comps,
Build: currentCom,
Original: originStr,
}
Expand Down

0 comments on commit 5926821

Please sign in to comment.