Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AIP-215): allow versioned subpackages #985

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
noahdietz marked this conversation as resolved.
Show resolved Hide resolved
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