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

Applying Google C++ styling using clang-format in pre-commit hook #5

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

drewoldag
Copy link
Collaborator

I've applied the Google C++ style guide to all the .cpp and .h files in .../src/lib using clang-format.
I checked that the code still compiled using make directly. There were a small number of files that needed some additional changes:

  • cosmology.h
  • ext.h
  • omp.h

As needed in each of those files, I added one or more of the following lines:

using std::ostream
using std::vector
using std::string

Given how common these are, I don't think there will be any namespace collisions, but please cross check this.

Additionally, I've added a pre-commit hook that will check and apply C++ style formatting for each commit. The file that defines the style rules is in .../.clang-format. Currently the only non-default rule is specifying that clang-format use the Google style rules as the default. Note that you can override those rules as desired.

… starting point. Apply formatting to all .cpp and .h files.
@drewoldag drewoldag requested a review from johannct March 13, 2024 23:31
@drewoldag drewoldag self-assigned this Mar 13, 2024
@drewoldag drewoldag linked an issue Mar 13, 2024 that may be closed by this pull request
Copy link
Member

@johannct johannct left a comment

Choose a reason for hiding this comment

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

Let's go with that. Does that mean that any push imperatively needs to be followed by a pull to be exactly equivalent to remote?

@drewoldag
Copy link
Collaborator Author

@johannct there's no need to push and then pull to keep your local branch up to date with main. The pre-commit hooks should do that for you. I saw your email about pre-commit getting in the way. I'll create another PR that removes most of the pre-commit hooks (but leaves the hook that will auto format your c++ code for you) and we can reintroduce them as we finish filling out this repository.

The typical workflow would then become:

  1. Add/edit c++ code
  2. Call git commit -m <message>
  3. pre-commit will run clang-format to clean up the formatting of the c++ code and report "FAILED" if it made changes.
  4. You review the changes and git add the files that were modified by clang-format
  5. Call git commit -m <message> again, this time clang-format will pass and the git commit is completed
  6. Call git push

@drewoldag drewoldag merged commit 8d066c3 into main Mar 14, 2024
2 of 5 checks passed
@drewoldag drewoldag deleted the issue/2/enforce-c-style-guide branch March 14, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC : indentation on C++ and python files
2 participants