fix: normalize license OR parentheses #12

Merged
misaka00251 merged 1 commits from Jvlegod/go2spec:fix-license-or-parentheses into master 2026-07-20 09:53:58 +00:00
2 changed files with 17 additions and 5 deletions
+8 -4
View File
@@ -358,10 +358,7 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
types = append(types, typ)
}
sort.Strings(types)
group := types[0]
if len(types) > 1 {
group = "(" + strings.Join(types, " OR ") + ")"
}
group := strings.Join(types, " OR ")
seenGroups[group] = true
}
if len(seenGroups) == 0 {
@@ -373,5 +370,12 @@ func pkgsiteLicenseExpression(licenses []pkgsiteLicense) string {
groups = append(groups, group)
}
sort.Strings(groups)
if len(groups) > 1 {
for i, group := range groups {
if strings.Contains(group, " OR ") {
groups[i] = "(" + group + ")"
}
}
}
return strings.Join(groups, " AND ")
}
+9 -1
View File
@@ -48,7 +48,15 @@ func TestPkgsiteLicenseExpression(t *testing.T) {
licenses: []pkgsiteLicense{
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
},
want: "(Apache-2.0 OR MIT)",
want: "Apache-2.0 OR MIT",
},
{
name: "parenthesizes OR group when joined with AND",
licenses: []pkgsiteLicense{
{FilePath: "LICENSE", Types: []string{"MIT", "Apache-2.0"}},
{FilePath: "COPYING", Types: []string{"BSD-3-Clause"}},
},
want: "(Apache-2.0 OR MIT) AND BSD-3-Clause",
},
{
name: "uses TODO when pkgsite has no SPDX type",