-
Notifications
You must be signed in to change notification settings - Fork 201
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
[WIP] pre-commit: set up clang-format hook #5687
base: development
Are you sure you want to change the base?
Conversation
Source/main.cpp
Outdated
warpx::initialization::initialize_external_libraries(argc, argv); | ||
{ | ||
WARPX_PROFILE_VAR("main()", pmain); | ||
|
||
auto timer = ablastr::utils::timer::Timer{}; | ||
timer.record_start_time(); | ||
|
||
auto& warpx = WarpX::GetInstance(); | ||
auto &warpx = WarpX::GetInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a formatting standard is a good idea - thanks!
However, my own preference is to have a space before and after the ampersand, since to me it is easier to read.
auto & warpx = WarpX::GetInstance();
In .clang-format
, this would be
ReferenceAlignment: Middle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @dpgrote! This is exactly the kind of feedback process I was hoping for regarding this formatting effort. I am personally fine with your preference, so I implemented the change. Others can chime in as well.
1ebb4fb
to
9e93f3b
Compare
We could also run the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree having a standard formatting would be great. The rules set so far look good to me and, as you said, we can refine as we go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, @EZoni ! I agree with @roelof-groenewald that having standard formatting is good.
About the rules that you have set, I have to confess that I am not a big fan of ReferenceAlignment: Middle
, because when I see something likeA & B
I immediately think or "A logical_and B" rather than "B is a reference to type A".
My personal preference on this point is left alignment, because when I see A&
I immediately think "type is reference to A". However, I agree that it is a bit less visible and I am OK with the other options for "ReferenceAlignment" if other maintainers prefer them.
Concerning the other rules that you have set, I like them!
Thanks, @lucafedeli88! If there are conflicting opinions on Note that the default LLVM style recommends |
|
Also interesting for more context, from Bjarne Stroustrup's C++ Style and Technique FAQ: https://www.stroustrup.com/bs_faq2.html#whitespace. |
Not sure if I shared this before, but we have clang-format integration in openPMD-api as a GH workflow & pre-commit hook: |
This PR introduces a prototype for adding the
clang-format
hook topre-commit
.To disable formatting, e.g., on blocks of mathematical formulas, use:
Currently, the hook is applied only to the
Source/main.cpp
file to demonstrate its functionality.If this approach is deemed useful, we can gradually extend it to all C++ files in our codebase, one PR at a time. We could make this into a GitHub "project" to easily keep track of the progress. If not, please feel free to close the PR without merging.
The
.clang-format
configuration file has been generated based on theLLVM
style using the commandclang-format -style=llvm -dump-config > .clang-format
and has been modified in the following ways:
A different base style could be chosen and/or further customization could be done in future PRs as needed, when the formatting is applied to more code.