Skip to content

Commit

Permalink
fix(AIP-215): allow versioned subpackages (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Jun 27, 2022
1 parent 12d16fb commit 5076b1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions rules/aip0215/versioned_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ var versionedPackages = &lint.FileRule{
}

// Ignore this if there is no package.
p := strings.Split(f.GetPackage(), ".")
if len(p) == 1 && p[0] == "" {
segments := strings.Split(f.GetPackage(), ".")
if len(segments) == 1 && segments[0] == "" {
return false
}

// Exempt anything ending in .type, or .v1master, .v2master, .master, etc.
if last := p[len(p)-1]; last == "type" || strings.HasSuffix(last, "master") || strings.HasSuffix(last, "main") {
return false
// Exempt anything containing .type, or .v1master, .v2master, .master, etc.
for _, segment := range segments {
if segment == "type" || strings.HasSuffix(segment, "master") || strings.HasSuffix(segment, "main") {
return false
}
}

// Everything else should follow the rule.
Expand All @@ -58,4 +60,4 @@ var versionedPackages = &lint.FileRule{
},
}

var version = regexp.MustCompile(`\.v[\d]+(p[\d]+)?(alpha|beta|eap|test)?[\d]*$`)
var version = regexp.MustCompile(`\.v[\d]+(p[\d]+)?(alpha|beta|eap|test)?[\d]*`)
4 changes: 3 additions & 1 deletion rules/aip0215/versioned_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func TestVersionedPackages(t *testing.T) {
{"Type", "package foo.bar.type;", testutils.Problems{}},
{"Master", "package foo.bar.master;", testutils.Problems{}},
{"VXMaster", "package foo.bar.v3master;", testutils.Problems{}},
{"ValidSubpackage", "package foo.bar.v1.resources;", testutils.Problems{}},
{"MasterSubpackage", "package foo.master.bar;", testutils.Problems{}},
{"VXMasterSubpackage", "package foo.v3master.bar;", testutils.Problems{}},
{"InvalidNoVersion", "package foo.bar;", testutils.Problems{{Message: "versioned packages"}}},
{"InvalidSubpackage", "package foo.bar.v1.resources;", testutils.Problems{{Message: "versioned packages"}}},
{"IgnoredRPC", "package google.rpc.foobar;", testutils.Problems{}},
{"IgnoredLRO", "package google.longrunning.foobar;", testutils.Problems{}},
{"IgnoredAPI", "package google.api.foobar;", testutils.Problems{}},
Expand Down

0 comments on commit 5076b1a

Please sign in to comment.