llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.95k stars 11.94k forks source link

When formatting protobuf, clang-format inserts a space after "keyword" inside field options #54848

Closed hexchain closed 1 month ago

hexchain commented 2 years ago

Protobuf keywords may appear in a field option, e.g. https://github.com/envoyproxy/protoc-gen-validate/blob/main/README.md#repeated. When formatting a file with such field option, clang-format insists on inserting a space after the "keyword".

Example file:

syntax = "proto3";
package proto.test;

message A {
  int32 a = 1;
}

message B {
  repeated A a = 1 [(annotation).int32.repeated.required.optional.oneof.test = true];
}

Output of clang-format --style=Google:

syntax = "proto3";
package proto.test;

message A {
  int32 a = 1;
}

message B {
  repeated A a = 1
      [(annotation).int32.repeated .required .optional .oneof.test = true];
}

Expected output:

No space should be inserted after "keywords" in a field option.

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-format

henryjhenry commented 2 months ago

this problem still occur

owenca commented 1 month ago

this problem still occur

Which version did you use? It seems to work with 18.1.8.

henryjhenry commented 1 month ago

this problem still occur

Which version did you use? It seems to work with 18.1.8.

clang-format: version 18.1.8 os: Apple M2 & OS 14.5 (23F79)

Using clang-format on .proto file:

proto:

message Req {
    repeated string IDs = 1 [(validate.rules).repeated.min_items = 1];
}

command:

 clang-format -style="{ IndentWidth: 4, BasedOnStyle: google, AlignConsecutiveAssignments: AcrossEmptyLines, AlignConsecutiveDeclarations: AcrossEmptyLines, ColumnLimit: 0, Language: Proto }"

got:

message Req {
    repeated string IDs = 1 [(validate.rules).repeated .min_items = 1];
}

There is a space between repeated and .min_items

llvmbot commented 1 month ago

@llvm/issue-subscribers-bug

Author: hexchain (hexchain)

Protobuf keywords may appear in a field option, e.g. https://github.com/envoyproxy/protoc-gen-validate/blob/main/README.md#repeated. When formatting a file with such field option, `clang-format` insists on inserting a space after the "keyword". Example file: ```proto syntax = "proto3"; package proto.test; message A { int32 a = 1; } message B { repeated A a = 1 [(annotation).int32.repeated.required.optional.oneof.test = true]; } ``` Output of `clang-format --style=Google`: ```proto syntax = "proto3"; package proto.test; message A { int32 a = 1; } message B { repeated A a = 1 [(annotation).int32.repeated .required .optional .oneof.test = true]; } ``` Expected output: No space should be inserted after "keywords" in a field option.