-
Notifications
You must be signed in to change notification settings - Fork 58
Add pre-commit and replace redundant CI lint steps #714
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright (c) 2026, An-Chi Liu <phy.tiger@gmail.com> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI files do not need copyright. |
||
| # BSD-style license; see COPYING | ||
| # | ||
| # See https://pre-commit.com for more information | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure an additional dependency for running the check is good. |
||
| # Run `pre-commit install` to set up the git hooks. | ||
| # Run `pre-commit run --all-files` to check the entire project. | ||
| # Run `pre-commit autoupdate` to update hook versions. | ||
| repos: | ||
| # C++ formatting | ||
| - repo: https://github.com/pre-commit/mirrors-clang-format | ||
| rev: v20.1.0 | ||
| hooks: | ||
| - id: clang-format | ||
| files: ^(cpp|gtests)/.*\.[ch]pp$ | ||
|
|
||
| # Python linting | ||
| - repo: https://github.com/PyCQA/flake8 | ||
| rev: 7.3.0 | ||
| hooks: | ||
| - id: flake8 | ||
| exclude: ^(thirdparty|tmp|_deps)/ | ||
|
|
||
| # Project-specific checks | ||
| - repo: local | ||
| hooks: | ||
| # Ensure C++ files use angle brackets for includes, not quotes | ||
| - id: cinclude | ||
| name: check-include-quotes | ||
| description: Ensure C++ includes use angle brackets, not quotes | ||
| entry: '#include\s*"' | ||
| language: pygrep | ||
| files: ^cpp/ | ||
|
|
||
| # Ensure source files contain only ASCII characters | ||
| - id: checkascii | ||
| name: check-ascii | ||
| description: Ensure source files contain only ASCII characters | ||
| entry: python3 contrib/lint/check_ascii.py | ||
| language: system | ||
| files: \.(py|cpp|hpp|c|h|cxx|hxx|sh|yml|yaml)$|(^|/)(CMakeLists\.txt|[Mm]akefile)$ | ||
| exclude: ^(tmp|_deps|build)/ | ||
|
|
||
| # Ensure source files have no trailing whitespace | ||
| - id: checktws | ||
| name: check-trailing-whitespace | ||
| description: Ensure source files have no trailing whitespace | ||
| entry: python3 contrib/lint/check_ascii.py --check-tws | ||
| language: system | ||
| files: \.(py|cpp|hpp|c|h|cxx|hxx|sh|yml|yaml)$|(^|/)(CMakeLists\.txt|[Mm]akefile)$ | ||
| exclude: ^(tmp|_deps|build)/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,20 @@ make flake8 # Python style check | |
| make checkascii # ASCII character check | ||
| ``` | ||
|
|
||
| ### Pre-commit | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let AI use pre-commit before it pushes the code. |
||
| ```bash | ||
| # Run all pre-commit hooks on staged files | ||
| pre-commit run | ||
|
|
||
| # Run all pre-commit hooks on the entire project | ||
| pre-commit run --all-files | ||
| ``` | ||
|
|
||
| **IMPORTANT**: Always run `pre-commit run --all-files` before committing and | ||
| pushing changes. This ensures clang-format, flake8, include-quote checks, | ||
| ASCII-only characters, and trailing whitespace checks all pass locally before | ||
| CI runs. | ||
|
|
||
| ### Cleanup | ||
| ```bash | ||
| # Clean build artifacts | ||
|
|
||
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.
Use pre-commit for CI to shorten the CI file.