-
Notifications
You must be signed in to change notification settings - Fork 33
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
Allow using clang-format for format the code #291
Conversation
d34b352
to
fa8ca5f
Compare
If you want to test different clang-format configurations, you can try this configurator. |
There is a plugin for Eclipse that integrates the clang-format tool as an alternative C/C++ code formatter. |
Several VSCode extension to clang-format are available (xaver's one is the most downloaded) |
We have a code style guide here. |
Sorry, my bad, i totally misunderstood. Please forget my previous comment (i'm going to delete it). Please proceed how you feel more appropriate. |
fa8ca5f
to
7a81260
Compare
Cool. Thanks @andrea-iob, I think this tool should be useful for all our developments.
Maybe I'm wrong, but I think that your deleted comment @roccoarpa was not off topic. In particular referring to
a couple of questions:
If not, I agree with @roccoarpa, maybe an internal meeting can be useful to inform all the developers, to discuss and to agree on a common coding style and to adopt it in all our Optimad codes. PS: I noticed that @andrea-iob already started a chat with some of us in this direction. |
188217b
to
7889de9
Compare
I've enabled alignment of consecutive macros, assignments, and bitfields (AlignConsecutiveMacros, AlignConsecutiveAssignments, AlignConsecutiveBitFields). |
Hello there: we run some test with the new formatting together with @kgkara, and the current format layout (with = alignment active) is fine for us. Anyway, I want to point out the question of the version of clang-format. I don't remember with which version this .clang-format yaml file is compliant. I used the version 12 (on Ubuntu newer version are not available with apt for now) and this file triggers error of unrecognized keys. I transferred the modifications on a clang12 compliant yaml (reported below) and this works. Let us know which version of clang-format will be officially supported in the end.
|
Let's use version 12. I will replace the .clang-format file with yours. |
7889de9
to
8efb13c
Compare
I've updated the .clang-format file. |
c6df8ca
to
494ad7e
Compare
For each module/test I added a target named |
494ad7e
to
8e69d92
Compare
For each module/test a target named clang-format-<name> is added. There is also a global target, called clang-format, that depends on all other clang-format targets.
8e69d92
to
98764c5
Compare
I updated the style guide and I did the following changes to the configuration file:
If there are no objections, I'm going to merge this pull request this week. After that, I will create additional pull requests for enforcing the coding style of the single bitpit modules. |
In order to keep the code style consistent among all bitpit modules, I've added to the root of the repository the configuration file needed by clang-format. The presence of this configuration file allows to use clang-format to automatically format the code:
The configuration filed is based on the LLVM coding standards (https://llvm.org/docs/CodingStandards.html). The changes with respect to the base configuration are minor: the width of the indentation and the placement of the braces. Here the difference between the base LLVM configuration:
If needed, the configuration can be changed (with the current one I get a code style very similar to the one we are currently using in some modules).
I've also added some scripts that allow to setup a pre-commit git hook to automatically format the code. The hook will inspect the code to be commited and, if it doesn't respect the code style, it will allow to automatically fix the coding style. This script can also be called manually to format individual files or staged changes. More information about the script here. The pre-commit hook can only be installed locally (see previous link), github doesn't support hooks. To enforce coding style on github, we can setup a github action that performs the check and allow merging a pull request only if the check is satisfied.
If needed, I can run clang-format on the whole code base or we can choose to apply the enforce the coding style only to the newly added code.