Skip to content

Conversation

Copy link

Copilot AI commented Jan 26, 2026

Adds .pre-commit-config.yaml with standard hooks for C++ development and code hygiene, along with contributor documentation and CI enforcement.

Hooks included

  • clang-format (v20.1.7) — formats C/C++ files using existing .clang-format
  • trailing-whitespace — strips trailing whitespace
  • end-of-file-fixer — ensures files end with newline
  • check-yaml — validates YAML syntax
  • check-added-large-files — prevents large file commits

Submodule Exclusion

Git submodules (test/benchmark/CGRA-Bench/ and test/benchmark/Zeonica_Testbench/) are excluded from all pre-commit hooks to prevent formatting files in external repositories.

Documentation

Updated README.md and CONTRIBUTING.md with pre-commit setup instructions for contributors, including explanation of automatic vs manual execution.

CI Integration

Added .github/workflows/pre-commit.yml workflow that runs pre-commit checks on all PRs and pushes to main, ensuring unformatted code cannot be merged.

Usage

pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-commit

Once installed, hooks run automatically on git commit. To manually check the entire codebase:

pre-commit run --all-files
Original prompt

You're a DevOps expert. Please add a .pre-commit-config.yaml file to the root of this repository.

Requirements:

  1. Include standard hooks for C++ development: clang-format (configured to use the existing .clang-format file), trailing-whitespace, and end-of-file-fixer.

  2. Include a hook for check-yaml and check-added-large-files.

  3. Once the file is created, create a new branch named feat/add-pre-commit-hooks, commit the change, and submit a Pull Request to the main branch with a clear description of these changes.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: BenkangPeng <143396699+BenkangPeng@users.noreply.github.com>
Copilot AI changed the title [WIP] Add pre-commit configuration for C++ development Add pre-commit hooks configuration for C++ development Jan 26, 2026
Copilot AI requested a review from BenkangPeng January 26, 2026 13:18
- id: check-added-large-files

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.6
Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot

  1. Shouldn't we add a newline at the end of .pre-commit-config.yaml?
  2. Add the content of precommit to CONTRIBUTING.md, guiding contributors to format code/files before sending pr/commit, e.g. pip install pre-commit, pre-commit install and pre-commit install --hook-type pre-commit.
  3. 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.

Copy link
Author

Choose a reason for hiding this comment

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

  1. The .pre-commit-config.yaml already ends with a newline.
  2. Added pre-commit setup instructions to CONTRIBUTING.md in 223f8ad, including pip install pre-commit, pre-commit install, and pre-commit install --hook-type pre-commit.
  3. 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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot

  1. Added pre-commit setup instructions to CONTRIBUTING.md in 223f8ad, including pip install pre-commit, pre-commit install, and pre-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?

  1. 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.

Copy link
Author

Choose a reason for hiding this comment

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

Done in a9b46a3:

  1. Clarified the documentation with a new "How it works" section explaining that hooks run automatically on git commit, and that pre-commit run --all-files is only needed for initial setup or checking the entire codebase.

  2. Added .github/workflows/pre-commit.yml CI workflow that runs pre-commit run --all-files on all PRs and pushes to main. This will prevent unformatted code from being merged.

Copy link
Collaborator

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

Copy link
Author

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.

Copy link
Collaborator

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?

Copy link
Author

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>
@tancheng
Copy link
Contributor

Sorry, what is this PR for? "pre-commit hooks configuration for C++ development"? I am not familiar with this...

@BenkangPeng
Copy link
Collaborator

Sorry, what is this PR for? "pre-commit hooks configuration for C++ development"? I am not familiar with this...

pre-commit is a tool that executes some jobs automatically, such as format code, delete unnecessary whitespaces, check yaml format and so on. That's to say, it will check all the staged files according to the above rules when we git commit. If the commit/staged files violates the above rules(i.e. there isn't a newline in some files), it will interrupt the commit, execute these jobs and remind us.

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.

@tancheng
Copy link
Contributor

It definitely helps. Thanks for the PR~!

@BenkangPeng
Copy link
Collaborator

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
Copy link
Contributor

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?

Copy link
Collaborator

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

Copy link
Collaborator

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

@tancheng
Copy link
Contributor

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?

Sure, feel free to do so. And plz leave instructions in readme about how to format the code before committing.

@BenkangPeng
Copy link
Collaborator

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>
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.

3 participants