https://bugs.llvm.org/show_bug.cgi?id=40360

            Bug ID: 40360
           Summary: clang-format indents protobuf incorrectly when an
                    option has a composite value
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangb...@nondot.org
          Reporter: jh...@bluegosling.com
                CC: djas...@google.com, kli...@google.com,
                    llvm-bugs@lists.llvm.org

I'm using clang-format on OS X to format protocol buffer sources.

--------------------------
$ clang-format --version
clang-format version 8.0.0 (tags/google/stable/2018-12-18)
--------------------------

I have a few proto source files that get improperly formatted. The indentation
is wrong: the formatter un-indents one too many after composite option value
ends.

Example protobuf code (test.proto):
--------------------------
syntax = "proto3";

package fullstory.users.v1;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "protoc-gen-swagger/options/annotations.proto";

option go_package = "users";

service Foo {
    rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty) {
        option (google.api.http).get = "/foo/bar";
        option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) =
{
            summary: "Query for foobar",
            description: "Query for a bar using a foo";
        };
    }
    rpc Baz(google.protobuf.Empty) returns (google.protobuf.Empty) {
        option (google.api.http).delete = "/foo/baz";
        option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) =
{
            summary: "Initiates a baz process",
            description: "Start processing a given baz";
        };
    }
}
--------------------------

The above is actually what I would expect the output of the formatter to be. So
if I run it through clang-format, I would expect no change. Instead, the last
several lines of the service get incorrectly un-indented.

--------------------------
$ clang-format '-style={BasedOnStyle: google, ColumnLimit: 150, IndentWidth: 4,
SpacesBeforeTrailingComments: 1, PenaltyBreakComment: 10}' < test.proto

syntax = "proto3";

package fullstory.users.v1;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "protoc-gen-swagger/options/annotations.proto";

option go_package = "users";

service Foo {
    rpc Bar(google.protobuf.Empty) returns(google.protobuf.Empty) {
        option(google.api.http).get = "/foo/bar";
        option(grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
            summary : "Query for foobar",
            description : "Query for a bar using a foo";
    };
}
rpc Baz(google.protobuf.Empty) returns(google.protobuf.Empty) {
    option(google.api.http).delete = "/foo/baz";
    option(grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
        summary : "Initiates a baz process",
        description : "Start processing a given baz";
};
}
}
--------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to