I cannot understand how does the following affect the formatting behavior in the clang format file:
RawStringFormats:
- Delimiters: [pb]
Language: TextProto
BasedOnStyle: google
Are these settings correct for a c++ project? (e.g. shouldn't the language be cpp?)
What does it mean 'pb' for Delimeters and how is it different from 'cc' and 'cpp'?
I tried to look for information inside clang documentations but it just adds to my confusion.
Clang-Format Style Options are flags that are supported by the ClangFormat tool, which became the de-facto standard to format C++ code. Clang offers the option to use one of the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or to create a custom configuration by using the given flags.
To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows. The workflow to format your changed code: Make codes changes in Electron repository.
clang-format file uses YAML format: key1: value1 key2: value2 # A comment. ... The configuration file can consist of several sections each having different Language: parameter denoting the programming language this section of the configuration is targeted at.
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
[pb]
as the delimiter there stands for ProtocolBuffers or Protobuf in short. The RawStringFormat
formatting option is specifically for acting as a hint to detect and format code fragments that appear as raw strings within the file (for supported languages); It uses the Delimiters
or the EnclosingFunctions
to detect and reformat them using the specified formatting style.
It could be useful even in a C++ project, if you want the formatting to be applied to raw strings in the file. For example, often C++ projects that uses protobuf input and output has test code that might look like:
InputProto ConstructInput() {
InputProto input;
Input *in = input.mutable_input();
in->set_id(10);
in->set_name("Test");
return in;
}
TEST(TestFoo, ComputesOut) {
OutputProto out;
out.set_result(200);
EXPECT_THAT(
GetOutput(ConstructInput()),
EqualsProto(outcome));
}
Protobuf allows you to write the same in a more human readable fashion using text format like so:
TEST(TestFoo, ComputesOut) {
EXPECT_THAT(
GetOutput(PARSE_TEXT_PROTO(R"pb(
input {
id: 10
name: "Test"
}
)")),
EqualsProto(PARSE_TEXT_PROTO(R"pb(
result: 200
)"))
);
}
And your formatting options would detect the text string within the pb
delimiter as protobuf code and reformat it using the google
formatting style.
Your settings are for formatting Google Protocol Buffers (https://developers.google.com/protocol-buffers) or short Protobuf.
If your C++ projects contains Protobuf descriptions the 'google' style formatting is applied.
I assume [pb] is short for Protobuf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With