-
Notifications
You must be signed in to change notification settings - Fork 15
Add pre-commit hooks configuration for C++ development #250
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
.pre-commit-config.yaml
Outdated
| - id: check-added-large-files | ||
|
|
||
| - repo: https://github.com/pre-commit/mirrors-clang-format | ||
| rev: v19.1.6 |
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.
@copilot Change the version of clang-format to v20.1.7
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.
Updated clang-format version to v20.1.7 in a51075f.
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.
- Shouldn't we add a newline at the end of
.pre-commit-config.yaml? - Add the content of
precommittoCONTRIBUTING.md, guiding contributors to format code/files before sending pr/commit, e.g.pip install pre-commit,pre-commit installandpre-commit install --hook-type pre-commit. - Should we add the pre-commit in CI? Is it the industry standard? Since if the contributor doesn't install the precommit and push the unformatted code, we have no idea to prevent it.
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.
- The
.pre-commit-config.yamlalready ends with a newline. - Added pre-commit setup instructions to
CONTRIBUTING.mdin 223f8ad, includingpip install pre-commit,pre-commit install, andpre-commit install --hook-type pre-commit. - Adding pre-commit to CI is indeed a common practice to enforce code style. This would typically be done by adding a workflow that runs
pre-commit run --all-files. I'd recommend creating a separate PR for the CI integration since that's a distinct change. The maintainers can decide if they want to proceed with that.
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.
- Added pre-commit setup instructions to
CONTRIBUTING.mdin 223f8ad, includingpip install pre-commit,pre-commit install, andpre-commit install --hook-type pre-commit.
We shouldn't always run pre-commit run --all-files, right? With pre-commit install --hook-type pre-commit, pre-commit will execute formatting tasks automatically before/when git commit, right? Maybe we should clarity this?
- Adding pre-commit to CI is indeed a common practice to enforce code style. This would typically be done by adding a workflow that runs
pre-commit run --all-files. I'd recommend creating a separate PR for the CI integration since that's a distinct change. The maintainers can decide if they want to proceed with that.
It's okay to continue to add per-commit test into CI in this pr. Send a new commit to finish it.
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.
Done in a9b46a3:
-
Clarified the documentation with a new "How it works" section explaining that hooks run automatically on
git commit, and thatpre-commit run --all-filesis only needed for initial setup or checking the entire codebase. -
Added
.github/workflows/pre-commit.ymlCI workflow that runspre-commit run --all-fileson all PRs and pushes to main. This will prevent unformatted code from being merged.
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.
@copilot Also add the guidance of precommit into README.md
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.
Added pre-commit guidance section to README.md in 15a1ecf. It includes setup instructions and a link to CONTRIBUTING.md for more details.
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.
@copilot Oh, will the pre-commit format the files of git submodules? If so, we need to exclude all the submodules, right?
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.
Good catch! Pre-commit could potentially process files in submodules when running pre-commit run --all-files. Added a global exclude pattern in 9810ee4 to skip the two submodule paths (test/benchmark/CGRA-Bench/ and test/benchmark/Zeonica_Testbench/).
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
|
Sorry, what is this PR for? "pre-commit hooks configuration for C++ development"? I am not familiar with this... |
I found there are some issues about formatting so I just let copilot to send this pr casually. And it needs a few minor modification.(please see here) Anyway, this is just a matter of code style and doesn't affect the functionality. Feel free to consider it or not. |
|
It definitely helps. Thanks for the PR~! |
|
Should I send a pr to format all the files? And should we also add the precommit in CI to prevent the unformatted code from merging? |
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
| - repo: https://github.com/pre-commit/mirrors-clang-format | ||
| rev: v20.1.7 | ||
| hooks: | ||
| - id: clang-format |
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.
are we able to set style = Google?
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.
Yes, we can change the code style to Google by modifying the .clang-format with clang-format --style=Google --dump-config > .clang-format
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.
We will transition from the LLVM code style to the Google code style.
CC @n0thingNoob @ShangkunLi @HobbitQia @YanzhouTang @guosran @MeowMJ
Sure, feel free to do so. And plz leave instructions in readme about how to format the code before committing. |
It would be better to format the whole codespace after merging the pending PRs, to avoid potential tricky conflicts. I will do that at the good time. |
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
Adds
.pre-commit-config.yamlwith standard hooks for C++ development and code hygiene, along with contributor documentation and CI enforcement.Hooks included
.clang-formatSubmodule Exclusion
Git submodules (
test/benchmark/CGRA-Bench/andtest/benchmark/Zeonica_Testbench/) are excluded from all pre-commit hooks to prevent formatting files in external repositories.Documentation
Updated
README.mdandCONTRIBUTING.mdwith pre-commit setup instructions for contributors, including explanation of automatic vs manual execution.CI Integration
Added
.github/workflows/pre-commit.ymlworkflow that runs pre-commit checks on all PRs and pushes to main, ensuring unformatted code cannot be merged.Usage
Once installed, hooks run automatically on
git commit. To manually check the entire codebase:Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.