Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format does not format RawString text protos correctly when there is TextProto specific config. #62871

Open
Icantjuddle opened this issue May 22, 2023 · 4 comments

Comments

@Icantjuddle
Copy link

Icantjuddle commented May 22, 2023

Given the following c++ code:

#include <string>
namespace {
std::string string = R"pb(
  my_msg {
    item: "asdfasdfasdfasdfasdfasdfsadf"
    item_three: "asdfasdfasdfasdfasdfasdfas"
    item_two: "asdadsadfsafdsafdsadfsafds"
  }
)pb";
}

It will format differently with no logical difference in the .clang-format

With just BasedOnStyle: Google it will format as above.

With the following:

---
BasedOnStyle: Google
---
Language: TextProto
...

I would expect it to format as above, however, instead it will format as:

#include <string>
namespace {
std::string string = R"pb(
  my_msg {
    item : "asdfasdfasdfasdfasdfasdfsadf"
    item_three : "asdfasdfasdfasdfasdfasdfas"
    item_two : "asdadsadfsafdsafdsadfsafds"
  }
)pb";
}

Re-pro unittest.

@llvmbot
Copy link
Collaborator

llvmbot commented May 22, 2023

@llvm/issue-subscribers-clang-format

@HazardyKnusperkeks
Copy link
Contributor

HazardyKnusperkeks commented May 23, 2023

And with

---
BasedOnStyle: Google
---
Language: TextProto
BasedOnStyle: Google
...

?

I think the error is in your assumption, not in Clang-Format.

@Icantjuddle
Copy link
Author

I think the error is in your assumption, not in clang-format.

Definitely possible, maybe you can help me better understand.
I think my core assumption is that the Language: X item at the beginning of a section means "all following configuration options in this section will only affect X language formatting, but by itself will not change anything."
Thus, adding an empty Language: X section should do nothing.

And with

With your suggested .clang_format it still formats with the spaces preceding the :s.

@HazardyKnusperkeks
Copy link
Contributor

I think the error is in your assumption, not in clang-format.

Definitely possible, maybe you can help me better understand. I think my core assumption is that the Language: X item at the beginning of a section means "all following configuration options in this section will only affect X language formatting, but by itself will not change anything." Thus, adding an empty Language: X section should do nothing.

And with

With your suggested .clang_format it still formats with the spaces preceding the :s.

That and krasimirs comment says it's a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants