Skip to content
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.6
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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/).

hooks:
- id: clang-format
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

types_or: [c++, c]