Repository: uber/prototool (go)

Issue:
Format: enum values lose options > 1
When more than one option is provided to an enum value, `prototool format` will strip out everything after the first one.

Example proto:
```protobuf
enum SomeEnum {
  SOME_ENUM_UNKNOWN = 0 [
    (option_1) = "a_value",
    (option_2) = "another_value"
  ];
}
```

From a quick look, this appears to be using [`EnumField.ValueOption`](https://godoc.org/github.com/emicklei/proto#EnumField) rather than `EnumField.Elements` in the format logic.


Pull request description:
Remove all references to proto.EnumField.ValueOption
Fixes #400.

Patch:
diff --git a/Makefile b/Makefile
index 4210c12..f41752a 100644
--- a/Makefile
+++ b/Makefile
@@ -144,6 +144,7 @@ grpcgen: $(CERTSTRAP)
 
 .PHONY: generate
 generate: license golden example internalgen bazelgen
+	gofmt -s -w $(SRCS)
 	go mod tidy -v
 
 .PHONY: checknodiffgenerated
@@ -175,7 +176,6 @@ errcheck: $(ERRCHECK)
 staticcheck: $(STATICCHECK)
 	staticcheck --tests=false $(PKGS)
 
-
 .PHONY: checklicense
 checklicense: $(UPDATE_LICENSE)
 	@echo update-license --dry $(SRCS)
diff --git a/internal/format/base_visitor.go b/internal/format/base_visitor.go
index 17c98bf..d9d4f8f 100644
--- a/internal/format/base_visitor.go
+++ b/internal/format/base_visitor.go
@@ -191,11 +191,13 @@ func isSingleValueLiteral(literal proto.Literal) bool {
 }
 
 func (v *baseVisitor) PEnumField(element *proto.EnumField) {
-	if element.ValueOption == nil {
-		v.pMessageOrEnumField("", element.Name, "", element.Integer, element.Comment, element.InlineComment)
-		return
+	var options []*proto.Option
+	for _, e := range element.Elements {
+		if option, ok := e.(*proto.Option); ok {
+			options = append(options, option)
+		}
 	}
-	v.pMessageOrEnumField("", element.Name, "", element.Integer, element.Comment, element.InlineComment, element.ValueOption)
+	v.pMessageOrEnumField("", element.Name, "", element.Integer, element.Comment, element.InlineComment, options...)
 }
 
 func cleanCommentLine(line string) string {
diff --git a/internal/lint/check_comments_no_c_style.go b/internal/lint/check_comments_no_c_style.go
index ac2e9f5..bba6fde 100644
--- a/internal/lint/check_comments_no_c_style.go
+++ b/internal/lint/check_comments_no_c_style.go
@@ -80,8 +80,8 @@ func (v commentsNoCStyleVisitor) VisitNormalField(element *proto.NormalField) {
 
 func (v commentsNoCStyleVisitor) VisitEnumField(element *proto.EnumField) {
 	v.checkComments(element.Position, element.Comment, element.InlineComment)
-	if element.ValueOption != nil {
-		element.ValueOption.Accept(v)
+	for _, child := range element.Elements {
+		child.Accept(v)
 	}
 }
 
diff --git a/internal/lint/check_comments_no_inline.go b/internal/lint/check_comments_no_inline.go
index 8d75476..33ca3da 100644
--- a/internal/lint/check_comments_no_inline.go
+++ b/internal/lint/check_comments_no_inline.go
@@ -76,8 +76,8 @@ func (v commentsNoInlineVisitor) VisitNormalField(element *proto.NormalField) {
 
 func (v commentsNoInlineVisitor) VisitEnumField(element *proto.EnumField) {
 	v.checkInlineComment("enum values", element.InlineComment)
-	if element.ValueOption != nil {
-		element.ValueOption.Accept(v)
+	for _, child := range element.Elements {
+		child.Accept(v)
 	}
 }
 
diff --git a/internal/lint/check_names.go b/internal/lint/check_names.go
index 511f5c8..8caf3b0 100644
--- a/internal/lint/check_names.go
+++ b/internal/lint/check_names.go
@@ -113,8 +113,8 @@ func (v *namesVisitor) VisitNormalField(element *proto.NormalField) {
 
 func (v *namesVisitor) VisitEnumField(element *proto.EnumField) {
 	v.checkName(element.Position, element.Name, element.Comment)
-	if element.ValueOption != nil {
-		element.ValueOption.Accept(v)
+	for _, child := range element.Elements {
+		child.Accept(v)
 	}
 }
 


Test patch:
diff --git a/internal/cmd/testdata/format/proto3/foo/foo.proto b/internal/cmd/testdata/format/proto3/foo/foo.proto
index 4114847..4bc8024 100644
--- a/internal/cmd/testdata/format/proto3/foo/foo.proto
+++ b/internal/cmd/testdata/format/proto3/foo/foo.proto
@@ -126,7 +126,8 @@ enum Something {
   option (bar.enum_option) = true;
 // comment25
   SOMETHING_INVALID = 0 [
-  (bar.enum_value_option) = true
+  (bar.enum_value_option) = true,
+  (bar.enum_value_dep_option) = { hello: 1, bar: 2, recursive: { hello: 3, recursive: { bar: 2 } } }
   ]; // inline comment25
 // comment27
   SOMETHING_UNSET = 1; // inline comment27
diff --git a/internal/cmd/testdata/format/proto3/foo/foo.proto.golden b/internal/cmd/testdata/format/proto3/foo/foo.proto.golden
index d968b86..ada18bc 100644
--- a/internal/cmd/testdata/format/proto3/foo/foo.proto.golden
+++ b/internal/cmd/testdata/format/proto3/foo/foo.proto.golden
@@ -163,7 +163,19 @@ message Empty {}
 enum Something {
   option (bar.enum_option) = true;
   // comment25
-  SOMETHING_INVALID = 0 [(bar.enum_value_option) = true]; // inline comment25
+  SOMETHING_INVALID = 0 [
+    (bar.enum_value_dep_option) = {
+      hello: 1
+      bar: 2
+      recursive: {
+        hello: 3
+        recursive: {
+          bar: 2
+        }
+      }
+    },
+    (bar.enum_value_option) = true
+  ]; // inline comment25
   // comment27
   SOMETHING_UNSET = 1; // inline comment27
   // comment28