-
Notifications
You must be signed in to change notification settings - Fork 180
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 formatting for C++ using clang-format #2652
Conversation
2ba33a0
to
a15b144
Compare
OK, I think this looks quite good now, and I think it's not a bad idea to merge this directly into dev. There are few things that need to be considered. Since we are enforcing the 100 words character limit, the scripts for generating the documentation and updating the copyright notice were broken. For the former, I directly updated the related rst files and adjusted the regular expressions needed to parse the configuration options and the environment variables in the code. For the latter, I adjusted the Other than that, everything looks good. |
🤦♂️ I'd written a bunch of stuff on this PR at some point, but clearly didn't hit the send button, and now can't find it unsubmitted on either system... I'll have another go, I can probably remember some of the code snippets I didn't like. Regarding destination branch / merge timing: I'd commented on Teams and in #2655 that there's a bunch of proposed modifications that aren't C++17 and therefore aren't #2585 / |
I think out of the c++17 changes, the only one that makes sense to deliver together with this PR is #2641. The way I see it is that this is (mostly) a formatting change, thus it shouldn't modify the behaviour of the code, while for example #2111 is a change that will affect the generated code (and most likely cannot really be automated because each macro usage will have to be evaluated before switching to |
(as far as I'm getting this evening; I might continue looking through more exemplar source files at a later date) |
Some examples of where stringently enforced line width causes ugliness: Old:
New:
Old:
New:
|
a87ee77
to
cff5cd8
Compare
1d2ab75
to
5c24401
Compare
c3911ee
to
9a3357b
Compare
c10c460
to
6ebc0dc
Compare
dc211e4
to
f109307
Compare
I've added a new script called I think this can now be merged in. This will require all existing and future PRs to format their code with |
@MRtrix3/mrtrix3-devs unless anyone have any reservations, I will merge this into dev soon. |
When clang-format, introduced in #2652, applied its changes to MRtrix3 code relating to the command-line interface (particularly the way that options and their arguments are concatenated through the addition operator), the resulting code was often quite ugly. This commit replaces code relating to CLI configuration (both the usage() function in cmd/*.cpp, and in definitions of options and option groups utilised by multiple commands) with manually formatted code, and includes comment fields to disable further manipulation of that code by clang-format.
When clang-format, introduced in #2652, applied its changes to MRtrix3 code relating to the command-line interface (particularly the way that options and their arguments are concatenated through the addition operator), the resulting code was often quite ugly. This commit replaces code relating to CLI configuration (both the usage() function in cmd/*.cpp, and in definitions of options and option groups utilised by multiple commands) with manually formatted code, and includes comment fields to disable further manipulation of that code by clang-format. This commit is a refactor of 0cec87a generated as part of #2815, with the changes being to omit other modifications to the command documentation that are not directly related to clang-format (those changes are in the parent commit to this commit: 15e253c), and to change authorship of the commit.
This pull request will introduce
clang-format
as the formatting tool for our C++ code. As discussed in #2643, this will provide consistency and a uniform formatting way for all developers.It contains a new CI workflow that checks whether new code is formatted correctly. It also contains a pre-commit configuration file to install a local git hook, which developers can use to ensure that their code is properly formatted before pushing.
Formatting has already been applied to all C++ files using the LLVM style with some custom settings (still needs tweaking).
Any suggestions or feedback is very welcome!