diff --git a/CHANGELOG.md b/CHANGELOG.md index 7694c98b08..4f42121a7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] -- No changes yet. +- Disable format on unknown or invalid syntax. ## [v1.60.0] - 2025-11-14 diff --git a/cmd/buf/testdata/format/invalid/invalid_field_number.proto b/cmd/buf/testdata/format/invalid/invalid_field_number.proto deleted file mode 100644 index 65c75fba34..0000000000 --- a/cmd/buf/testdata/format/invalid/invalid_field_number.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -message FieldWithoutFieldNumber { - required string field; // missing field number - optional string withoptions [ - (syntax) = true - ]; -} diff --git a/private/buf/bufformat/bufformat.go b/private/buf/bufformat/bufformat.go index 36af57e719..ec72155e03 100644 --- a/private/buf/bufformat/bufformat.go +++ b/private/buf/bufformat/bufformat.go @@ -82,6 +82,12 @@ func FormatBucket(ctx context.Context, bucket storage.ReadBucket) (_ storage.Rea // FormatFileNode formats the given file node and writ the result to dest. func FormatFileNode(dest io.Writer, fileNode *ast.FileNode) error { + // Construct the file descriptor to ensure the AST is valid. This will + // capture unknown syntax like edition "2024" which at the current time is + // not supported. + if _, err := parser.ResultFromAST(fileNode, true, reporter.NewHandler(nil)); err != nil { + return err + } formatter := newFormatter(dest, fileNode) return formatter.Run() } diff --git a/private/buf/bufformat/formatter_test.go b/private/buf/bufformat/formatter_test.go index 36fdfe2a7a..5b5c592774 100644 --- a/private/buf/bufformat/formatter_test.go +++ b/private/buf/bufformat/formatter_test.go @@ -42,7 +42,8 @@ func testFormatCustomOptions(t *testing.T) { } func testFormatEditions(t *testing.T) { - testFormatNoDiff(t, "testdata/editions") + testFormatNoDiff(t, "testdata/editions/2023") + testFormatError(t, "testdata/editions/2024", `edition "2024" not yet fully supported; latest supported edition "2023"`) } func testFormatProto2(t *testing.T) { @@ -78,40 +79,54 @@ func testFormatNoDiff(t *testing.T, path string) { ctx := context.Background() bucket, err := storageos.NewProvider().NewReadWriteBucket(path) require.NoError(t, err) + moduleSetBuilder := bufmodule.NewModuleSetBuilder(ctx, slogtestext.NewLogger(t), bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) moduleSetBuilder.AddLocalModule(bucket, path, true) moduleSet, err := moduleSetBuilder.Build() require.NoError(t, err) - readBucket, err := FormatModuleSet(ctx, moduleSet) + formatBucket, err := FormatModuleSet(ctx, moduleSet) require.NoError(t, err) - require.NoError( - t, - storage.WalkReadObjects( + assertGolden := func(formatBucket storage.ReadBucket) { + err := storage.WalkReadObjects( ctx, - readBucket, + formatBucket, "", func(formattedFile storage.ReadObject) error { - expectedPath := formattedFile.Path() - t.Run(expectedPath, func(t *testing.T) { - // The expected format result is the golden file. If - // this file IS a golden file, it is expected to not - // change. - if !strings.HasSuffix(expectedPath, ".golden.proto") { - expectedPath = strings.Replace(expectedPath, ".proto", ".golden.proto", 1) - } - formattedData, err := io.ReadAll(formattedFile) - require.NoError(t, err) - expectedFile, err := bucket.Get(ctx, expectedPath) - require.NoError(t, err) - expectedData, err := io.ReadAll(expectedFile) - require.NoError(t, err) - fileDiff, err := diff.Diff(ctx, expectedData, formattedData, expectedPath, formattedFile.Path()+" (formatted)") - require.NoError(t, err) - require.Empty(t, string(fileDiff)) - }) + formattedData, err := io.ReadAll(formattedFile) + require.NoError(t, err) + expectedPath := strings.Replace(formattedFile.Path(), ".proto", ".golden", 1) + expectedData, err := storage.ReadPath(ctx, bucket, expectedPath) + require.NoError(t, err) + fileDiff, err := diff.Diff(ctx, expectedData, formattedData, expectedPath, formattedFile.Path()+" (formatted)") + require.NoError(t, err) + require.Empty(t, string(fileDiff)) return nil }, - ), - ) + ) + require.NoError(t, err) + } + assertGolden(formatBucket) + + moduleSetBuilder = bufmodule.NewModuleSetBuilder(ctx, slogtestext.NewLogger(t), bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) + moduleSetBuilder.AddLocalModule(formatBucket, path, true) + moduleSet, err = moduleSetBuilder.Build() + require.NoError(t, err) + reformattedBucket, err := FormatModuleSet(ctx, moduleSet) + require.NoError(t, err) + assertGolden(reformattedBucket) + }) +} + +func testFormatError(t *testing.T, path string, errContains string) { + t.Run(path, func(t *testing.T) { + ctx := context.Background() + bucket, err := storageos.NewProvider().NewReadWriteBucket(path) + require.NoError(t, err) + moduleSetBuilder := bufmodule.NewModuleSetBuilder(ctx, slogtestext.NewLogger(t), bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) + moduleSetBuilder.AddLocalModule(bucket, path, true) + moduleSet, err := moduleSetBuilder.Build() + require.NoError(t, err) + _, err = FormatModuleSet(ctx, moduleSet) + require.ErrorContains(t, err, errContains) }) } diff --git a/private/buf/bufformat/testdata/customoptions/options.golden.proto b/private/buf/bufformat/testdata/customoptions/options.golden similarity index 100% rename from private/buf/bufformat/testdata/customoptions/options.golden.proto rename to private/buf/bufformat/testdata/customoptions/options.golden diff --git a/private/buf/bufformat/testdata/editions/editions.golden.proto b/private/buf/bufformat/testdata/editions/2023/editions.golden similarity index 100% rename from private/buf/bufformat/testdata/editions/editions.golden.proto rename to private/buf/bufformat/testdata/editions/2023/editions.golden diff --git a/private/buf/bufformat/testdata/editions/editions.proto b/private/buf/bufformat/testdata/editions/2023/editions.proto similarity index 100% rename from private/buf/bufformat/testdata/editions/editions.proto rename to private/buf/bufformat/testdata/editions/2023/editions.proto diff --git a/private/buf/bufformat/testdata/editions/2024/editions.proto b/private/buf/bufformat/testdata/editions/2024/editions.proto new file mode 100644 index 0000000000..2ec2daa42e --- /dev/null +++ b/private/buf/bufformat/testdata/editions/2024/editions.proto @@ -0,0 +1,5 @@ +edition = "2024"; + +package a.b.c; + +import option "google/protobuf/descriptor.proto"; diff --git a/private/buf/bufformat/testdata/header/nopackage.golden.proto b/private/buf/bufformat/testdata/header/nopackage.golden similarity index 100% rename from private/buf/bufformat/testdata/header/nopackage.golden.proto rename to private/buf/bufformat/testdata/header/nopackage.golden diff --git a/private/buf/bufformat/testdata/header/nosyntax.golden.proto b/private/buf/bufformat/testdata/header/nosyntax.golden similarity index 100% rename from private/buf/bufformat/testdata/header/nosyntax.golden.proto rename to private/buf/bufformat/testdata/header/nosyntax.golden diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto2/enum/v1/empty.golden similarity index 69% rename from private/buf/bufformat/testdata/proto2/enum/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto2/enum/v1/empty.golden index 335352e96b..89c9748aba 100644 --- a/private/buf/bufformat/testdata/proto2/enum/v1/empty.golden.proto +++ b/private/buf/bufformat/testdata/proto2/enum/v1/empty.golden @@ -1,11 +1,14 @@ enum Foo { + FOO_UNKNOWN = 1; /* C-style comment in the middle */ } enum Bar { + BAR_UNKNOWN = 1; // Normal comment in the middle } enum Baz { + BAZ_UNKNOWN = 1; // Body comment. } diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/empty.proto b/private/buf/bufformat/testdata/proto2/enum/v1/empty.proto index 62889b2967..a3b3a5743e 100644 --- a/private/buf/bufformat/testdata/proto2/enum/v1/empty.proto +++ b/private/buf/bufformat/testdata/proto2/enum/v1/empty.proto @@ -1,10 +1,11 @@ -enum Foo { /* C-style comment in the middle */ } +enum Foo { FOO_UNKNOWN = 1; /* C-style comment in the middle */ } enum Bar { + BAR_UNKNOWN = 1; // Normal comment in the middle } enum Baz { - + BAZ_UNKNOWN = 1; // Body comment. } diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/enum.golden.proto b/private/buf/bufformat/testdata/proto2/enum/v1/enum.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/enum/v1/enum.golden.proto rename to private/buf/bufformat/testdata/proto2/enum/v1/enum.golden diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_comment.golden.proto b/private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_comment.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_comment.golden.proto rename to private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_comment.golden diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_newline.golden.proto b/private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_newline.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_newline.golden.proto rename to private/buf/bufformat/testdata/proto2/enum/v1/enum_trailing_newline.golden diff --git a/private/buf/bufformat/testdata/proto2/enum/v1/enum_value_trailing_comment.golden.proto b/private/buf/bufformat/testdata/proto2/enum/v1/enum_value_trailing_comment.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/enum/v1/enum_value_trailing_comment.golden.proto rename to private/buf/bufformat/testdata/proto2/enum/v1/enum_value_trailing_comment.golden diff --git a/private/buf/bufformat/testdata/proto2/extend/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto2/extend/v1/empty.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/extend/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto2/extend/v1/empty.golden diff --git a/private/buf/bufformat/testdata/proto2/field/v1/option.golden.proto b/private/buf/bufformat/testdata/proto2/field/v1/option.golden similarity index 96% rename from private/buf/bufformat/testdata/proto2/field/v1/option.golden.proto rename to private/buf/bufformat/testdata/proto2/field/v1/option.golden index e536bbd18f..19a84dabfa 100644 --- a/private/buf/bufformat/testdata/proto2/field/v1/option.golden.proto +++ b/private/buf/bufformat/testdata/proto2/field/v1/option.golden @@ -21,7 +21,7 @@ message Foo { */ // Leading comment on name_with_options. - string name_with_options = 2 [ + optional string name_with_options = 2 [ (custom.float_field_option) = "nan", (custom.double_field_option) = "inf", (custom.int32_field_option) = -3, diff --git a/private/buf/bufformat/testdata/proto2/field/v1/option.proto b/private/buf/bufformat/testdata/proto2/field/v1/option.proto index 5198083429..e55b299d26 100644 --- a/private/buf/bufformat/testdata/proto2/field/v1/option.proto +++ b/private/buf/bufformat/testdata/proto2/field/v1/option.proto @@ -18,7 +18,7 @@ message Foo { */ // Leading comment on name_with_options. - string name_with_options = 2 [ + optional string name_with_options = 2 [ (custom.float_field_option) = "nan", (custom.double_field_option) = "inf", (custom.int32_field_option) = -3, diff --git a/private/buf/bufformat/testdata/proto2/group/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto2/group/v1/empty.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/group/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto2/group/v1/empty.golden diff --git a/private/buf/bufformat/testdata/proto2/header/v1/import.golden.proto b/private/buf/bufformat/testdata/proto2/header/v1/import.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/header/v1/import.golden.proto rename to private/buf/bufformat/testdata/proto2/header/v1/import.golden diff --git a/private/buf/bufformat/testdata/proto2/header/v1/option.golden.proto b/private/buf/bufformat/testdata/proto2/header/v1/option.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/header/v1/option.golden.proto rename to private/buf/bufformat/testdata/proto2/header/v1/option.golden diff --git a/private/buf/bufformat/testdata/proto2/header/v1/package.golden.proto b/private/buf/bufformat/testdata/proto2/header/v1/package.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/header/v1/package.golden.proto rename to private/buf/bufformat/testdata/proto2/header/v1/package.golden diff --git a/private/buf/bufformat/testdata/proto2/license/v1/enum.golden.proto b/private/buf/bufformat/testdata/proto2/license/v1/enum.golden similarity index 57% rename from private/buf/bufformat/testdata/proto2/license/v1/enum.golden.proto rename to private/buf/bufformat/testdata/proto2/license/v1/enum.golden index 2c110f70e1..8d5cd94dbe 100644 --- a/private/buf/bufformat/testdata/proto2/license/v1/enum.golden.proto +++ b/private/buf/bufformat/testdata/proto2/license/v1/enum.golden @@ -4,5 +4,9 @@ before the enums. */ -enum Foo {} -enum Bar {} +enum Foo { + FOO_UNKNOWN = 1; +} +enum Bar { + BAR_UNKNOWN = 1; +} diff --git a/private/buf/bufformat/testdata/proto2/license/v1/enum.proto b/private/buf/bufformat/testdata/proto2/license/v1/enum.proto index d4a8895676..98cd96689f 100644 --- a/private/buf/bufformat/testdata/proto2/license/v1/enum.proto +++ b/private/buf/bufformat/testdata/proto2/license/v1/enum.proto @@ -5,5 +5,5 @@ */ -enum Foo {} -enum Bar {} +enum Foo { FOO_UNKNOWN = 1;} +enum Bar {BAR_UNKNOWN=1;} diff --git a/private/buf/bufformat/testdata/proto2/license/v1/message.golden.proto b/private/buf/bufformat/testdata/proto2/license/v1/message.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/license/v1/message.golden.proto rename to private/buf/bufformat/testdata/proto2/license/v1/message.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/empty.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/empty.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/message.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/message.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/message.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message_extensions.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/message_extensions.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/message_extensions.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/message_extensions.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message_group.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/message_group.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/message_group.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/message_group.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message_import.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/message_import.golden similarity index 68% rename from private/buf/bufformat/testdata/proto2/message/v1/message_import.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/message_import.golden index bf35bdaffc..b69cbd3d31 100644 --- a/private/buf/bufformat/testdata/proto2/message/v1/message_import.golden.proto +++ b/private/buf/bufformat/testdata/proto2/message/v1/message_import.golden @@ -4,7 +4,7 @@ import "custom.proto"; message Thing { // Trailing comment on '}'. // Leading comment on thing field. - custom.Thing thing = 1; // Trailing comment on thing field. + optional custom.Thing thing = 1; // Trailing comment on thing field. // Leading comment on '}', } diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message_import.proto b/private/buf/bufformat/testdata/proto2/message/v1/message_import.proto index 66ded869ad..fcd75d1dd4 100644 --- a/private/buf/bufformat/testdata/proto2/message/v1/message_import.proto +++ b/private/buf/bufformat/testdata/proto2/message/v1/message_import.proto @@ -5,7 +5,7 @@ import "custom.proto"; message Thing { // Trailing comment on '}'. // Leading comment on thing field. - custom.Thing thing = 1; // Trailing comment on thing field. + optional custom.Thing thing = 1; // Trailing comment on thing field. // Leading comment on '}', } diff --git a/private/buf/bufformat/testdata/proto2/message/v1/message_options.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/message_options.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/message_options.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/message_options.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden similarity index 90% rename from private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden index bacd6977d8..2119f7d50e 100644 --- a/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden.proto +++ b/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.golden @@ -14,7 +14,7 @@ message Foo { } // Comment on the nested Baz message. message Baz { - string something = 5; + optional string something = 5; // Comment on the nested Qux message. message Qux { @@ -22,7 +22,7 @@ message Foo { option no_standard_descriptor_accessor = false; - string another = 6; + optional string another = 6; } } } diff --git a/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.proto b/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.proto index 8134d974dd..2e96425ba4 100644 --- a/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.proto +++ b/private/buf/bufformat/testdata/proto2/message/v1/multiple_nested.proto @@ -14,9 +14,9 @@ syntax = "proto2"; /* This one is required */ required bool /* Between 'bool' and 'truth' */ truth = 3; } // Comment on the nested Baz message. - message Baz { - - string something = 5; + message Baz { + + optional string something = 5; // Comment on the nested Qux message. message Qux { @@ -24,7 +24,7 @@ syntax = "proto2"; option no_standard_descriptor_accessor = false; - string another = 6; + optional string another = 6; } } diff --git a/private/buf/bufformat/testdata/proto2/message/v1/nested.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/nested.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/message/v1/nested.golden.proto rename to private/buf/bufformat/testdata/proto2/message/v1/nested.golden diff --git a/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden b/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden new file mode 100644 index 0000000000..fd5df6c0e4 --- /dev/null +++ b/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden @@ -0,0 +1,9 @@ +syntax = "proto2"; + +message Foo { + // This is a trailing comment on the '{'. + + optional string name = 1; + + optional string value = 2; // In-line on value. +} diff --git a/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden.proto b/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden.proto deleted file mode 100644 index 1416bd125d..0000000000 --- a/private/buf/bufformat/testdata/proto2/message/v1/sparse.golden.proto +++ /dev/null @@ -1,7 +0,0 @@ -message Foo { - // This is a trailing comment on the '{'. - - string name = 1; - - string value = 2; // In-line on value. -} diff --git a/private/buf/bufformat/testdata/proto2/message/v1/sparse.proto b/private/buf/bufformat/testdata/proto2/message/v1/sparse.proto index ab7e323535..b5c67e8d8a 100644 --- a/private/buf/bufformat/testdata/proto2/message/v1/sparse.proto +++ b/private/buf/bufformat/testdata/proto2/message/v1/sparse.proto @@ -1,4 +1,6 @@ -message +syntax = "proto2"; + +message Foo @@ -8,9 +10,9 @@ message // This is a trailing comment on the '{'. - string name = 1; + optional string name = 1; - string value = 2; // In-line on value. + optional string value = 2; // In-line on value. } diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/option/v1/option.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option.golden diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_array.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_array.golden similarity index 88% rename from private/buf/bufformat/testdata/proto2/option/v1/option_array.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option_array.golden index c3248f7afe..fc4bc11ae2 100644 --- a/private/buf/bufformat/testdata/proto2/option/v1/option_array.golden.proto +++ b/private/buf/bufformat/testdata/proto2/option/v1/option_array.golden @@ -4,7 +4,7 @@ import "custom.proto"; message Foo { message Bar { - string name = 1 [(custom.field_thing_option) = { + optional string name = 1 [(custom.field_thing_option) = { // Trailing comment on '{'. // Leading comment on repeated_foo field. diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_array.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_array.proto index c782c4f459..4197655fbf 100644 --- a/private/buf/bufformat/testdata/proto2/option/v1/option_array.proto +++ b/private/buf/bufformat/testdata/proto2/option/v1/option_array.proto @@ -4,7 +4,7 @@ import "custom.proto"; message Foo { message Bar { - string name = 1 [ + optional string name = 1 [ (custom.field_thing_option) = { // Trailing comment on '{'. diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_complex_array_literal.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_complex_array_literal.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/option/v1/option_complex_array_literal.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option_complex_array_literal.golden diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_compound_name.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_compound_name.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/option/v1/option_compound_name.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option_compound_name.golden diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_message_field.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_message_field.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/option/v1/option_message_field.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option_message_field.golden diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_name.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_name.golden similarity index 93% rename from private/buf/bufformat/testdata/proto2/option/v1/option_name.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/option_name.golden index 3327eb806b..7188a06273 100644 --- a/private/buf/bufformat/testdata/proto2/option/v1/option_name.golden.proto +++ b/private/buf/bufformat/testdata/proto2/option/v1/option_name.golden @@ -13,7 +13,7 @@ extend google.protobuf.FieldOptions { message Foo { option (/* One */ something /* Two */) = 1; - string name = 1 [ + optional string name = 1 [ // Leading comment on deprecated. deprecated /* After deprecated */ = true, // Leading comment on another. diff --git a/private/buf/bufformat/testdata/proto2/option/v1/option_name.proto b/private/buf/bufformat/testdata/proto2/option/v1/option_name.proto index eb0fd828ec..e3e86691a8 100644 --- a/private/buf/bufformat/testdata/proto2/option/v1/option_name.proto +++ b/private/buf/bufformat/testdata/proto2/option/v1/option_name.proto @@ -13,7 +13,7 @@ extend google.protobuf.FieldOptions { message Foo { option (/* One */ something /* Two */) = 1; - string name = 1 [ + optional string name = 1 [ // Leading comment on deprecated. deprecated /* After deprecated */ = true, // Leading comment on another. diff --git a/private/buf/bufformat/testdata/proto2/option/v1/single_compact_option.golden.proto b/private/buf/bufformat/testdata/proto2/option/v1/single_compact_option.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/option/v1/single_compact_option.golden.proto rename to private/buf/bufformat/testdata/proto2/option/v1/single_compact_option.golden diff --git a/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden b/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden new file mode 100644 index 0000000000..11520e9701 --- /dev/null +++ b/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden @@ -0,0 +1,24 @@ +syntax = "proto2"; + +import "google/protobuf/descriptor.proto"; + +message Foo { + optional string something = 1; +} + +extend google.protobuf.FieldOptions { + optional string name = 10001; + optional Foo foo = 10002; +} + +message Foo { + optional string one = 1 [(name) = "f\"o\"'o'"]; + optional string two = 2 [(name) = 'f"oo"']; + optional string three = 3 [(name) = "f'oo'"]; + optional string four = 4 [(name) = "f\"o\"\'o\'"]; + optional string five = 5 [(name) = "f\"o\"o"]; + optional string six = 6 [(name) = 'f\'o\'o']; + optional string seven = 7 [(name) = "foo"]; + optional string eight = 8 [(foo) = {something: 'something:"foo"'}]; + optional string nine = 9 [(foo) = {something: "something:\"foo\"\nanother:\"bar\""}]; +} diff --git a/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden.proto b/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden.proto deleted file mode 100644 index 64bb8915e5..0000000000 --- a/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.golden.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto2"; - -import "google/protobuf/descriptor.proto"; - -message Foo { - string something = 1; -} - -extend google.protobuf.FieldOptions { - string name = 10001; - Foo foo = 10002; -} - -message Foo { - string one = 1 [(name) = "f\"o\"'o'"]; - string two = 2 [(name) = 'f"oo"']; - string three = 3 [(name) = "f'oo'"]; - string four = 4 [(name) = "f\"o\"\'o\'"]; - string five = 5 [(name) = "f\"o\"o"]; - string six = 6 [(name) = 'f\'o\'o']; - string seven = 7 [(name) = "foo"]; - string eight = 8 [(foo) = {something: 'something:"foo"'}]; - string nine = 9 [(foo) = {something: "something:\"foo\"\nanother:\"bar\""}]; -} diff --git a/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.proto b/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.proto index 9d18033c72..886942a0c5 100644 --- a/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.proto +++ b/private/buf/bufformat/testdata/proto2/quotes/v1/quotes.proto @@ -3,26 +3,26 @@ syntax = "proto2"; import "google/protobuf/descriptor.proto"; message Foo { - string something = 1; + optional string something = 1; } extend google.protobuf.FieldOptions { - string name = 10001; - Foo foo = 10002; + optional string name = 10001; + optional Foo foo = 10002; } message Foo { - string one = 1 [(name) = "f\"o\"'o'"]; - string two = 2 [(name) = 'f"oo"']; - string three = 3 [(name) = "f'oo'"]; - string four = 4 [(name) = "f\"o\"\'o\'"]; - string five = 5 [(name) = "f\"o\"o"]; - string six = 6 [(name) = 'f\'o\'o']; - string seven = 7 [(name) = "foo"]; - string eight = 8 [(foo) = { + optional string one = 1 [(name) = "f\"o\"'o'"]; + optional string two = 2 [(name) = 'f"oo"']; + optional string three = 3 [(name) = "f'oo'"]; + optional string four = 4 [(name) = "f\"o\"\'o\'"]; + optional string five = 5 [(name) = "f\"o\"o"]; + optional string six = 6 [(name) = 'f\'o\'o']; + optional string seven = 7 [(name) = "foo"]; + optional string eight = 8 [(foo) = { something: 'something:"foo"' }]; - string nine = 9 [(foo) = { + optional string nine = 9 [(foo) = { something: "something:\"foo\"\nanother:\"bar\"" }]; } diff --git a/private/buf/bufformat/testdata/proto2/utf8/v1/utf8.golden.proto b/private/buf/bufformat/testdata/proto2/utf8/v1/utf8.golden similarity index 100% rename from private/buf/bufformat/testdata/proto2/utf8/v1/utf8.golden.proto rename to private/buf/bufformat/testdata/proto2/utf8/v1/utf8.golden diff --git a/private/buf/bufformat/testdata/proto3/all/v1/all.golden.proto b/private/buf/bufformat/testdata/proto3/all/v1/all.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/all/v1/all.golden.proto rename to private/buf/bufformat/testdata/proto3/all/v1/all.golden diff --git a/private/buf/bufformat/testdata/proto3/block/v1/block.golden.proto b/private/buf/bufformat/testdata/proto3/block/v1/block.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/block/v1/block.golden.proto rename to private/buf/bufformat/testdata/proto3/block/v1/block.golden diff --git a/private/buf/bufformat/testdata/proto3/block/v1/block.proto b/private/buf/bufformat/testdata/proto3/block/v1/block.proto new file mode 100644 index 0000000000..8371a74e1e --- /dev/null +++ b/private/buf/bufformat/testdata/proto3/block/v1/block.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package block.v1; + +/* + This comment has an empty line with no comment below this sentence. + + The formatter should not output any indentation on the above line. +*/ + +message Baz {} diff --git a/private/buf/bufformat/testdata/proto3/file/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto3/file/v1/empty.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/file/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto3/file/v1/empty.golden diff --git a/private/buf/bufformat/testdata/proto3/file/v1/eof.golden.proto b/private/buf/bufformat/testdata/proto3/file/v1/eof.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/file/v1/eof.golden.proto rename to private/buf/bufformat/testdata/proto3/file/v1/eof.golden diff --git a/private/buf/bufformat/testdata/proto3/file/v1/option.golden.proto b/private/buf/bufformat/testdata/proto3/file/v1/option.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/file/v1/option.golden.proto rename to private/buf/bufformat/testdata/proto3/file/v1/option.golden diff --git a/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.golden.proto b/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.golden.proto deleted file mode 100644 index 4e3c3ebd08..0000000000 --- a/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.golden.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; /* - timestamp will preserve commented imports - field_mask will preserve the first one - empty will preserve default import - annotation will preserve the normal import -*/ - -import "google/protobuf/annotation.proto"; -import "google/protobuf/empty.proto"; -import "google/protobuf/field_mask.proto"; -// commented import will not be removed -import "google/protobuf/timestamp.proto"; -import /*commented*/ "google/protobuf/timestamp.proto"; -import "google/protobuf/timestamp.proto"; //commented diff --git a/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.proto b/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.proto deleted file mode 100644 index d5d76964ea..0000000000 --- a/private/buf/bufformat/testdata/proto3/header/v1/duplicate_import.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3";/* -timestamp will preserve commented imports -field_mask will preserve the first one -empty will preserve default import -annotation will preserve the normal import -*/ - -import "google/protobuf/timestamp.proto"; -// commented import will not be removed -import "google/protobuf/timestamp.proto"; -import /*commented*/ "google/protobuf/timestamp.proto"; -import "google/protobuf/timestamp.proto"; //commented - -import "google/protobuf/field_mask.proto"; -import "google/protobuf/field_mask.proto"; - -import "google/protobuf/empty.proto"; -import public "google/protobuf/empty.proto"; -import weak "google/protobuf/empty.proto"; - -import "google/protobuf/annotation.proto"; -import weak "google/protobuf/annotation.proto"; \ No newline at end of file diff --git a/private/buf/bufformat/testdata/proto3/header/v1/header-block.golden.proto b/private/buf/bufformat/testdata/proto3/header/v1/header-block.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/header/v1/header-block.golden.proto rename to private/buf/bufformat/testdata/proto3/header/v1/header-block.golden diff --git a/private/buf/bufformat/testdata/proto3/header/v1/header.golden.proto b/private/buf/bufformat/testdata/proto3/header/v1/header.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/header/v1/header.golden.proto rename to private/buf/bufformat/testdata/proto3/header/v1/header.golden diff --git a/private/buf/bufformat/testdata/proto3/header/v1/unused_import.golden.proto b/private/buf/bufformat/testdata/proto3/header/v1/unused_import.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/header/v1/unused_import.golden.proto rename to private/buf/bufformat/testdata/proto3/header/v1/unused_import.golden diff --git a/private/buf/bufformat/testdata/proto3/literal/v1/compound_string.golden.proto b/private/buf/bufformat/testdata/proto3/literal/v1/compound_string.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/literal/v1/compound_string.golden.proto rename to private/buf/bufformat/testdata/proto3/literal/v1/compound_string.golden diff --git a/private/buf/bufformat/testdata/proto3/literal/v1/literal.golden.proto b/private/buf/bufformat/testdata/proto3/literal/v1/literal.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/literal/v1/literal.golden.proto rename to private/buf/bufformat/testdata/proto3/literal/v1/literal.golden diff --git a/private/buf/bufformat/testdata/proto3/literal/v1/literal_comments.golden.proto b/private/buf/bufformat/testdata/proto3/literal/v1/literal_comments.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/literal/v1/literal_comments.golden.proto rename to private/buf/bufformat/testdata/proto3/literal/v1/literal_comments.golden diff --git a/private/buf/bufformat/testdata/proto3/literal/v1/special_literal.golden.proto b/private/buf/bufformat/testdata/proto3/literal/v1/special_literal.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/literal/v1/special_literal.golden.proto rename to private/buf/bufformat/testdata/proto3/literal/v1/special_literal.golden diff --git a/private/buf/bufformat/testdata/proto3/oneof/v1/multiple.golden.proto b/private/buf/bufformat/testdata/proto3/oneof/v1/multiple.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/oneof/v1/multiple.golden.proto rename to private/buf/bufformat/testdata/proto3/oneof/v1/multiple.golden diff --git a/private/buf/bufformat/testdata/proto3/oneof/v1/simple.golden.proto b/private/buf/bufformat/testdata/proto3/oneof/v1/simple.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/oneof/v1/simple.golden.proto rename to private/buf/bufformat/testdata/proto3/oneof/v1/simple.golden diff --git a/private/buf/bufformat/testdata/proto3/range/v1/range.golden.proto b/private/buf/bufformat/testdata/proto3/range/v1/range.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/range/v1/range.golden.proto rename to private/buf/bufformat/testdata/proto3/range/v1/range.golden diff --git a/private/buf/bufformat/testdata/proto3/service/v1/empty.golden.proto b/private/buf/bufformat/testdata/proto3/service/v1/empty.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/service/v1/empty.golden.proto rename to private/buf/bufformat/testdata/proto3/service/v1/empty.golden diff --git a/private/buf/bufformat/testdata/proto3/service/v1/empty_rpc.golden.proto b/private/buf/bufformat/testdata/proto3/service/v1/empty_rpc.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/service/v1/empty_rpc.golden.proto rename to private/buf/bufformat/testdata/proto3/service/v1/empty_rpc.golden diff --git a/private/buf/bufformat/testdata/proto3/service/v1/service.golden.proto b/private/buf/bufformat/testdata/proto3/service/v1/service.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/service/v1/service.golden.proto rename to private/buf/bufformat/testdata/proto3/service/v1/service.golden diff --git a/private/buf/bufformat/testdata/proto3/service/v1/service_options.golden.proto b/private/buf/bufformat/testdata/proto3/service/v1/service_options.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/service/v1/service_options.golden.proto rename to private/buf/bufformat/testdata/proto3/service/v1/service_options.golden diff --git a/private/buf/bufformat/testdata/proto3/service/v1/simple.golden.proto b/private/buf/bufformat/testdata/proto3/service/v1/simple.golden similarity index 100% rename from private/buf/bufformat/testdata/proto3/service/v1/simple.golden.proto rename to private/buf/bufformat/testdata/proto3/service/v1/simple.golden diff --git a/private/bufpkg/bufparse/full_name.go b/private/bufpkg/bufparse/full_name.go index 8a2111ce27..cc8ad10581 100644 --- a/private/bufpkg/bufparse/full_name.go +++ b/private/bufpkg/bufparse/full_name.go @@ -27,11 +27,11 @@ type FullName interface { // String returns "registry/owner/name". fmt.Stringer - // Registry returns the hostname of the BSR instance that this is contained within. + // Registry returns the hostname of the BSR instance that this entity is contained within. Registry() string - // Owner returns the name of the user or organization that owns this . + // Owner returns the name of the user or organization that owns this entity. Owner() string - // Name returns the name of the . + // Name returns the name of the entity. Name() string isFullName()