buf icon indicating copy to clipboard operation
buf copied to clipboard

Preserve single quotes with buf format

Open thinkgos opened this issue 3 years ago • 2 comments

before:

message LoginRequest {
  string name = 1 [
    (gogoproto.moretags) = 'binding:"required"',
    (google.api.field_behavior) = REQUIRED
  ];
  string passwd = 2 [
    (gogoproto.moretags) = 'binding:"required"',
    (google.api.field_behavior) = REQUIRED
  ];
}

after run buf format.

message LoginRequest {
  string name = 1 [
    (gogoproto.moretags) = "binding:\"required\"",
    (google.api.field_behavior) = REQUIRED
  ];
  string passwd = 2 [
    (gogoproto.moretags) = "binding:\"required\"",
    (google.api.field_behavior) = REQUIRED
  ];
}

it is alway use double quote for string, then Escape the double quote.

thinkgos avatar Apr 28 '22 05:04 thinkgos

Thanks for the issue - we should be able to detect whether or not the string contains a double quote and preserve the format in the original source. I'll need to do a little bit of investigation to determine exactly where single quotes can be used in the prototext format (it could just be anywhere a double quote string is, but perhaps not).

amckinney avatar Apr 28 '22 16:04 amckinney

is there any progress?

lkzz avatar Jul 26 '22 06:07 lkzz

This will go out in the next release!

amckinney avatar Aug 12 '22 00:08 amckinney