Repository: googleapis/api-linter
Pull request #449 (2019-12-12 20:00:19)

[fix] Make Java annotation rules resilient against Google internal tool.
…ols.


Patch:
diff --git a/rules/aip0191/java_multiple_files.go b/rules/aip0191/java_multiple_files.go
index 90dc686..2b1275c 100644
--- a/rules/aip0191/java_multiple_files.go
+++ b/rules/aip0191/java_multiple_files.go
@@ -15,14 +15,18 @@
 package aip0191
 
 import (
+	"strings"
+
 	"github.com/googleapis/api-linter/lint"
 	"github.com/googleapis/api-linter/locations"
 	"github.com/jhump/protoreflect/desc"
 )
 
 var javaMultipleFiles = &lint.FileRule{
-	Name:   lint.NewRuleName(191, "java-multiple-files"),
-	OnlyIf: hasPackage,
+	Name: lint.NewRuleName(191, "java-multiple-files"),
+	OnlyIf: func(f *desc.FileDescriptor) bool {
+		return hasPackage(f) && !strings.HasSuffix(f.GetPackage(), ".master")
+	},
 	LintFile: func(f *desc.FileDescriptor) []lint.Problem {
 		if !f.GetFileOptions().GetJavaMultipleFiles() {
 			return []lint.Problem{{
diff --git a/rules/aip0191/java_outer_classname.go b/rules/aip0191/java_outer_classname.go
index cac9b51..549cd9d 100644
--- a/rules/aip0191/java_outer_classname.go
+++ b/rules/aip0191/java_outer_classname.go
@@ -26,8 +26,10 @@ import (
 )
 
 var javaOuterClassname = &lint.FileRule{
-	Name:   lint.NewRuleName(191, "java-outer-classname"),
-	OnlyIf: hasPackage,
+	Name: lint.NewRuleName(191, "java-outer-classname"),
+	OnlyIf: func(f *desc.FileDescriptor) bool {
+		return hasPackage(f) && !strings.HasSuffix(f.GetPackage(), ".master")
+	},
 	LintFile: func(f *desc.FileDescriptor) []lint.Problem {
 		if f.GetFileOptions().GetJavaOuterClassname() == "" {
 			filename := filepath.Base(f.GetName())


Test patch:
diff --git a/rules/aip0191/java_multiple_files_test.go b/rules/aip0191/java_multiple_files_test.go
index b5683e5..71146d1 100644
--- a/rules/aip0191/java_multiple_files_test.go
+++ b/rules/aip0191/java_multiple_files_test.go
@@ -30,6 +30,7 @@ func TestJavaMultipleFiles(t *testing.T) {
 		{"Valid", "package foo.v1;", "option java_multiple_files = true;", testutils.Problems{}},
 		{"Invalid", "package foo.v1;", "", testutils.Problems{{Message: "java_multiple_files"}}},
 		{"Ignored", "", "", testutils.Problems{}},
+		{"IgnoredMaster", "package foo.master;", "", testutils.Problems{}},
 	} {
 		t.Run(test.name, func(t *testing.T) {
 			f := testutils.ParseProto3Tmpl(t, `
diff --git a/rules/aip0191/java_outer_classname_test.go b/rules/aip0191/java_outer_classname_test.go
index f66451b..9bdcf73 100644
--- a/rules/aip0191/java_outer_classname_test.go
+++ b/rules/aip0191/java_outer_classname_test.go
@@ -33,6 +33,7 @@ func TestJavaOuterClassname(t *testing.T) {
 		{"Invalid", "test.proto", []string{"package foo.v1;", ""}, testutils.Problems{{Message: `java_outer_classname = "TestProto"`}}},
 		{"InvalidWithPath", "foo/bar/test.proto", []string{"package foo.v1;"}, testutils.Problems{{Message: `java_outer_classname = "TestProto"`}}},
 		{"Ignored", "test.proto", []string{"", ""}, testutils.Problems{}},
+		{"IgnoredMaster", "test.proto", []string{"package foo.master;", ""}, testutils.Problems{}},
 	} {
 		t.Run(test.name, func(t *testing.T) {
 			f := testutils.ParseProto3String(t, strings.Join(test.statements, "\n"))