From 086468c8921dcc4c468bc9d26e4084011b356859 Mon Sep 17 00:00:00 2001 From: Josh Humphries <2035234+jhump@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:42:37 -0500 Subject: [PATCH 1/2] more option locations in image source info --- private/bufpkg/bufimage/bufimagebuild/builder.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/private/bufpkg/bufimage/bufimagebuild/builder.go b/private/bufpkg/bufimage/bufimagebuild/builder.go index cd8a8c39ca..b9a969a3d9 100644 --- a/private/bufpkg/bufimage/bufimagebuild/builder.go +++ b/private/bufpkg/bufimage/bufimagebuild/builder.go @@ -310,7 +310,10 @@ func getBuildResult( ) *buildResult { var errorsWithPos []reporter.ErrorWithPos var warningErrorsWithPos []reporter.ErrorWithPos - sourceInfoMode := protocompile.SourceInfoStandard + // With "extra option locations", buf can include more comments + // for an option value than protoc can. In particular, this allows + // it to preserve comments inside of message literals. + sourceInfoMode := protocompile.SourceInfoExtraOptionLocations if excludeSourceCodeInfo { sourceInfoMode = protocompile.SourceInfoNone } From 0f6ac2472d9c360a9512e52a7d230a4487b1a61c Mon Sep 17 00:00:00 2001 From: Josh Humphries <2035234+jhump@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:07:22 -0500 Subject: [PATCH 2/2] update test --- private/bufpkg/bufcheck/buflint/buflint_test.go | 3 ++- .../buflint/testdata/protovalidate_rules/number.proto | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/private/bufpkg/bufcheck/buflint/buflint_test.go b/private/bufpkg/bufcheck/buflint/buflint_test.go index 09f60c2e0f..e049cfc7f9 100644 --- a/private/bufpkg/bufcheck/buflint/buflint_test.go +++ b/private/bufpkg/bufcheck/buflint/buflint_test.go @@ -625,7 +625,8 @@ func TestRunProtovalidateRules(t *testing.T) { bufanalysistesting.NewFileAnnotation(t, "number.proto", 35, 5, 35, 43, "PROTOVALIDATE"), bufanalysistesting.NewFileAnnotation(t, "number.proto", 39, 5, 39, 43, "PROTOVALIDATE"), bufanalysistesting.NewFileAnnotation(t, "number.proto", 42, 5, 42, 42, "PROTOVALIDATE"), - bufanalysistesting.NewFileAnnotation(t, "number.proto", 45, 48, 48, 4, "PROTOVALIDATE"), + bufanalysistesting.NewFileAnnotation(t, "number.proto", 46, 5, 46, 11, "PROTOVALIDATE"), + bufanalysistesting.NewFileAnnotation(t, "number.proto", 47, 5, 47, 12, "PROTOVALIDATE"), bufanalysistesting.NewFileAnnotation(t, "number.proto", 56, 5, 56, 39, "PROTOVALIDATE"), bufanalysistesting.NewFileAnnotation(t, "number.proto", 65, 5, 65, 41, "PROTOVALIDATE"), bufanalysistesting.NewFileAnnotation(t, "number.proto", 74, 5, 74, 40, "PROTOVALIDATE"), diff --git a/private/bufpkg/bufcheck/buflint/testdata/protovalidate_rules/number.proto b/private/bufpkg/bufcheck/buflint/testdata/protovalidate_rules/number.proto index e1425556c4..834dacd082 100644 --- a/private/bufpkg/bufcheck/buflint/testdata/protovalidate_rules/number.proto +++ b/private/bufpkg/bufcheck/buflint/testdata/protovalidate_rules/number.proto @@ -41,10 +41,10 @@ message Int32Test { // the next line should be annotated (buf.validate.field).sfixed64.gt = 10 ]; - // the entire option should be annotated. (45, 48) to (48, 4) + // annotating items inside an option value fixed32 invalid_bound_aggregate_syntax = 11 [(buf.validate.field).fixed32 = { - lt: 10 - gte: 10 + lt: 10 // this line should be annotated + gte: 10 // and this one, too }]; // valid google.protobuf.Int32Value int32_value_match = 12 [