Repository: googleapis/api-linter (go)

Issue:
API Lint rule 126, Should not check for alias enum type
 if the first enum type is also an alias, then an API lint error will occur. Say enum Type { option allow_alias = true; TYPE_UNSPECIFIED = 0; DEFAULT_TYPE = 0; TYPE_ONE = 1; } This type enum alias, in my understanding should be allowed.

Pull request:
[AIP-216] support alias
Resolve #466
- check if at least one enum with <name>_UNSPECIFIED
- check if <name>_UNSPECIFIED = 0
- added alias test case.

Patch:
diff --git a/rules/aip0126/unspecified.go b/rules/aip0126/unspecified.go
index 4aae186..f34f30b 100644
--- a/rules/aip0126/unspecified.go
+++ b/rules/aip0126/unspecified.go
@@ -24,25 +24,21 @@ import (
 	"github.com/stoewer/go-strcase"
 )
 
-var unspecified = &lint.EnumValueRule{
-	Name:   lint.NewRuleName(126, "unspecified"),
-	OnlyIf: isFirstEnumValue,
-	LintEnumValue: func(v *desc.EnumValueDescriptor) []lint.Problem {
-		want := strings.ToUpper(strcase.SnakeCase(v.GetEnum().GetName()) + "_UNSPECIFIED")
-		if v.GetName() != want {
-			return []lint.Problem{{
-				Message:    fmt.Sprintf("The first enum value should be %q", want),
-				Suggestion: want,
-				Descriptor: v,
-				Location:   locations.DescriptorName(v),
-			}}
+var unspecified = &lint.EnumRule{
+	Name: lint.NewRuleName(126, "unspecified"),
+	LintEnum: func(e *desc.EnumDescriptor) []lint.Problem {
+		firstValue := e.GetValues()[0]
+		want := strings.ToUpper(strcase.SnakeCase(e.GetName()) + "_UNSPECIFIED")
+		for _, element := range e.GetValues() {
+			if element.GetName() == want && element.GetNumber() == 0 {
+				return nil
+			}
 		}
-
-		return nil
+		return []lint.Problem{{
+			Message:    fmt.Sprintf("The first enum value should be %q", want),
+			Suggestion: want,
+			Descriptor: firstValue,
+			Location:   locations.DescriptorName(firstValue),
+		}}
 	},
 }
-
-// Note: proto3 requires that first value in enum have numeric value of 0.
-func isFirstEnumValue(v *desc.EnumValueDescriptor) bool {
-	return v.GetNumber() == 0
-}


Test patch:
diff --git a/rules/aip0126/unspecified_test.go b/rules/aip0126/unspecified_test.go
index b974125..e49befc 100644
--- a/rules/aip0126/unspecified_test.go
+++ b/rules/aip0126/unspecified_test.go
@@ -42,6 +42,25 @@ func TestUnspecified(t *testing.T) {
 				}
 			`, test)
 
+			// Run the lint rule and establish we get the correct problems.
+			problems := unspecified.Lint(f)
+			if diff := test.problems.SetDescriptor(f.GetEnumTypes()[0].GetValues()[0]).Diff(problems); diff != "" {
+				t.Errorf(diff)
+			}
+		})
+	}
+	for _, test := range tests {
+		t.Run(test.testName, func(t *testing.T) {
+			// Create the proto with the enum.
+			f := testutils.ParseProto3Tmpl(t, `
+				enum BookFormat {
+					option allow_alias = true; 
+					HARDBACK = 0;
+					{{.ValueName}} = 0;
+					PAPERBACK = 1;
+				}
+			`, test)
+
 			// Run the lint rule and establish we get the correct problems.
 			problems := unspecified.Lint(f)
 			if diff := test.problems.SetDescriptor(f.GetEnumTypes()[0].GetValues()[0]).Diff(problems); diff != "" {