Skip to content

Commit

Permalink
refactor: return nil instead of an empty slice
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 23, 2024
1 parent 8f7feab commit e8cc083
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 8 deletions.
4 changes: 0 additions & 4 deletions pkg/lockfile/parse-npm-lock-v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,20 @@ func TestParseNpmLock_v1_NestedDependenciesDup(t *testing.T) {
Version: "6.1.0",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
})

expectPackage(t, packages, lockfile.PackageDetails{
Name: "supports-color",
Version: "5.5.0",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
})

expectPackage(t, packages, lockfile.PackageDetails{
Name: "supports-color",
Version: "2.0.0",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
})
}

Expand Down Expand Up @@ -448,7 +445,6 @@ func TestParseNpmLock_v1_SamePackageDifferentGroups(t *testing.T) {
Version: "5.5.2",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
},
})
}
3 changes: 0 additions & 3 deletions pkg/lockfile/parse-npm-lock-v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,12 @@ func TestParseNpmLock_v2_NestedDependenciesDup(t *testing.T) {
Version: "6.1.0",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
},
{
Name: "supports-color",
Version: "2.0.0",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
},
})
}
Expand Down Expand Up @@ -440,7 +438,6 @@ func TestParseNpmLock_v2_SamePackageDifferentGroups(t *testing.T) {
Version: "5.5.2",
Ecosystem: lockfile.NpmEcosystem,
CompareAs: lockfile.NpmEcosystem,
DepGroups: []string{},
},
})
}
2 changes: 1 addition & 1 deletion pkg/lockfile/parse-npm-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type npmPackageDetailsMap map[string]PackageDetails
func mergeNpmDepsGroups(a, b PackageDetails) []string {
// if either group includes no groups, then the package is in the "production" group
if len(a.DepGroups) == 0 || len(b.DepGroups) == 0 {
return []string{}
return nil
}

combined := make([]string, 0, len(a.DepGroups)+len(b.DepGroups))
Expand Down

0 comments on commit e8cc083

Please sign in to comment.