diff --git a/rules/aip0215/versioned_packages.go b/rules/aip0215/versioned_packages.go index 31224a366..af7a5bf8d 100644 --- a/rules/aip0215/versioned_packages.go +++ b/rules/aip0215/versioned_packages.go @@ -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. @@ -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]*`) diff --git a/rules/aip0215/versioned_packages_test.go b/rules/aip0215/versioned_packages_test.go index 96c362020..8a711b415 100644 --- a/rules/aip0215/versioned_packages_test.go +++ b/rules/aip0215/versioned_packages_test.go @@ -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{}},