diff --git a/pkg/format/formatter.go b/pkg/format/formatter.go index 53804bb..03068fd 100644 --- a/pkg/format/formatter.go +++ b/pkg/format/formatter.go @@ -760,6 +760,10 @@ func columnFormatElements[T ast.Node, C elementsContainer[T]](f *formatter, ctr default: shouldStartNewGroup = false } + case *ast.FieldNode: + if prevNode.Options != nil && !f.compactOptionsShouldBeExpanded(prevNode.Options) { + shouldStartNewGroup = false + } } } diff --git a/pkg/format/formatter_test.go b/pkg/format/formatter_test.go index 9e1ba8e..50d1b35 100644 --- a/pkg/format/formatter_test.go +++ b/pkg/format/formatter_test.go @@ -210,21 +210,46 @@ message Foo { // comment 1 // comment 2 ]; +}`[1:], + }, + 13: { + input: ` +message Foo { +reserved 50; // comment +repeated string field1 = 52; +optional string field2 = 84 [ (opt) = {foo: true, bar: ENUM_VALUE} +]; +optional string field3 = 101; +optional string field4 = 102 [(opt).test = true]; +optional bool field5 = 106; +optional Aaaaaaaaaaaaaaaaaaaaaa field6 = 116;} +`[1:], + want: ` +message Foo { + reserved 50; // comment + repeated string field1 = 52; + optional string field2 = 84 [(opt) = {foo: true, bar: ENUM_VALUE}]; + optional string field3 = 101; + optional string field4 = 102 [(opt).test = true]; + optional bool field5 = 106; + optional Aaaaaaaaaaaaaaaaaaaaaa field6 = 116; }`[1:], }, } - for i, c := range cases[12:] { - if c.want == "" { - c.want = c.input - } + for i, c := range cases { + t.Run("", func(t *testing.T) { + if c.want == "" { + c.want = c.input + } - root, err := parser.Parse("", strings.NewReader(c.input), reporter.NewHandler(nil), 0) - require.NoError(t, err) + root, err := parser.Parse("", strings.NewReader(c.input), reporter.NewHandler(nil), 0) + require.NoError(t, err) - got, err := format.PrintNode(root, root) - require.NoError(t, err) + got, err := format.PrintNode(root, root) + require.NoError(t, err) - require.Equal(t, c.want, got, "case %d", i) + require.Equal(t, c.want, got, "case %d", i) + }) } }