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

Apply clang-format to the code base #255

Merged
merged 1 commit into from
Aug 3, 2022

Conversation

Neverlord
Copy link
Member

  • Apply clang-format to the entire code base
  • Enable clang-format checks for PRs

Aside from the obvious benefit of forcing a consistent coding style, this PR is also a preparation step for running clang-tidy. Some clang-tidy checks can automatically provide a fix for certain findings. However, when applying such tool-assisted code changes, we also need to run clang-format afterwards to make sure the code stays consistently formatted.

@Neverlord Neverlord force-pushed the topic/neverlord/clang-format branch from d8b754a to 87b96a4 Compare July 9, 2022 08:16
@Neverlord
Copy link
Member Author

I've ended up excluding the code under tests/benchmark/readerwriterqueue/. The diff had some very weird looking code changes and that code is very unlikely to change. Maybe removing that code is actually the better call, but I'd prefer doing that separately.

Copy link
Member

@timwoj timwoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it through the whole thing. One general comment is that we're missing a .clang-format file. Even if we're just using one of the default styles, we probably should have one just to be explicit about what style we're opting for.

bindings/python/set_bind.h Outdated Show resolved Hide resolved
std::is_copy_constructible<typename Set::value_type>::value, Class_> &cl) {
template <typename, typename, typename... Args>
void set_if_copy_constructible(const Args&...) {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to have empty brace sets on the same line.

.def("publish_batch",
[](broker::publisher& p, std::vector<broker::data> xs) { p.publish(xs); })
.def("publish", (void(broker::publisher::*)(broker::data d))
& broker::publisher::publish)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is separating the & from the variable name, if the intention is for it to be taking the address of that variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either was clang-format is thinking about this code. Maybe it confuses this with an argument declaration. Although, then it should put the & after the brace... 🤷🏻‍♂️


// Wait until connection is established.
for ( bool has_peer = false; !has_peer; ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a weird mix of the Zeek style and whatever broker uses by default. There's actually a flag you can pass to clang-format to preserve this style, if that's what we want to do (SpacesInConditionalStatement). It doesn't look like we prefer this format everywhere else though, so I'm fine with letting it go.

include/broker/detail/filesystem.hh Show resolved Hide resolved
include/broker/detail/radix_tree.hh Show resolved Hide resolved
include/broker/internal/type_id.hh Show resolved Hide resolved
src/internal/master_actor.cc Show resolved Hide resolved
tests/cpp/backend.cc Show resolved Hide resolved
tests/cpp/core.cc Show resolved Hide resolved
@Neverlord Neverlord force-pushed the topic/neverlord/clang-format branch from 1808f44 to f331e55 Compare July 30, 2022 07:07
@Neverlord
Copy link
Member Author

@timwoj I've tweaked the coding style based on your suggestions:

  • keep = on the line above
  • allow empty functions on a single line

I've also tweaked the penalties so that clang-format generally tries to avoid putting the return type on a single line and I had some cases where clang-format would break in the middle of a structured binding after putting = on the line above without some tuning (setting PenaltyBreakAssignment to 21 is the sweetspot apparently).

Let me know if it needs further tweaking. If you prefer, I can also squash the commits before a merge (kept the second commit for now to allow you to review the changes).

@Neverlord
Copy link
Member Author

Also, should've mentioned that his PR relates #249.

Copy link
Member

@timwoj timwoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now. clang-format is just weird sometimes, so the rest of the questions I had can just stay the way they are.

@Neverlord Neverlord force-pushed the topic/neverlord/clang-format branch from f331e55 to a4e6e6c Compare August 3, 2022 17:10
@Neverlord Neverlord force-pushed the topic/neverlord/clang-format branch from a4e6e6c to 7e11326 Compare August 3, 2022 17:13
@Neverlord Neverlord marked this pull request as ready for review August 3, 2022 18:45
@Neverlord Neverlord merged commit 1084bd4 into master Aug 3, 2022
@Neverlord Neverlord deleted the topic/neverlord/clang-format branch August 3, 2022 18:45
Neverlord added a commit that referenced this pull request Aug 20, 2022
For #255, we ran `clang-format` over the code base. By accident, we've
also formatted `BrokerConfig.cmake.in` and broke CMake packaging in the
process by changing `@PACKAGE_INIT@` to `@PACKAGE_INIT @`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants