-
Notifications
You must be signed in to change notification settings - Fork 79
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
Script and Workflows for automatic code formating #175
Conversation
The |
Hi Tim, Thanks for this. The formatting rules look good to me. |
Yeah, I totally see the problem with the history. However, I somehow don't get why it helps to split these into two commits? Can you elaborate? I just learned there is an option for |
So if I look at the link you provided with the changes made, then git seems to have issues to map the lines adequately. Instead, it is making huge blocks of removed/added stuff. I dont think the .git_blame_ignore_revs will work. My guess/experience with git is that if you e.g. only do limited trailing whitespace changes (but not whitespace / line breaks inside a line) it handles it better. My hope would be that then the blocks that are deleted/added are smaller and thus more easy to understand the original source later. |
.github/workflows/formatapply.yml
Outdated
clangFormatVersion: 12 | ||
style: file | ||
inplace: True | ||
- uses: EndBug/add-and-commit@v4 |
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.
Maybe it is a bit safer to open a PR instead of directly pushing a new commit? There are Github actions for automatically opening PRs.
…irectly). Also, it adds relevant hashs to a .git-blame-ignore-revs.
This PR adds automatic code formatting facilities (using
clang-format
).Code Formatting with Continuous Integration
Two GitHub workflows are added:
check-code-format
fails if the code is currently not formatted correctly. This action is triggered for every push and for every pull request.apply-code-format
actually applies the code formatting andcommitscreates a pull request (like this) containing all necessary changes. It also adds commit hashes to a new.git-blame-ignore-revs
file so thatgit blame
remains (more or less) usable. Theapply-code-format
has to be triggered manually.All source code files in
./src
. are considered, where the file.clang-format-ignore
lists directory path patterns that are excluded. Currently, everything related to DFTs, POMDPs, and parametric models is excluded.Code Formatting Locally
This PR also adds a script for applying code formatting locally. The script can be invoked via a new make target. In the
build
directory, we can now runmake format
to apply the formatting to all files (without committing anything).
Alternatively, most IDEs (e.g. CLion) can be configured in a way that code formatting is applied automatically when saving.
Our
.clang-format
configuration currently requiresclang-format
to be available in at least version12
.Once this PR is merged, the plan is to (manually) trigger the
apply-code-format
action so that formatting will be applied to the existing codebase. This is what will happen.Further notes:
?w=1
to the URL) so that we can see what the formatter is actually doing..clang-format
configuration that disables function definitions and if-statements in a single line.