Add code duplication detection to pre-commit#80
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideConfigures a new pre-commit hook using the lizard tool to detect code duplication and complexity issues in C, C++, and Python files as part of the existing pre-commit pipeline. Flow diagram for pre-commit execution including new lizard hookflowchart TD
A[Start git commit] --> B[pre-commit triggers]
B --> C[Run existing hooks
for configured files]
C --> D[Run lizard hook
with args
--languages c,cpp,python]
D --> E{Any lizard issues
reported?}
E -- Yes --> F[Fail commit
show duplication and
complexity issues]
E -- No --> G[Proceed to next
pre-commit steps or
complete commit]
F --> H[Developer fixes issues
and retries commit]
H --> B
G --> I[Commit succeeds]
I --> J[End]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning Rate limit exceeded@Liam-Deacon has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 24 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider constraining the lizard hook to your actual source tree (e.g.,
files/excludepatterns) so that third-party, generated, or tooling scripts aren’t inadvertently scanned and cause noisy duplication/complexity findings. - It may be helpful to explicitly set lizard thresholds (e.g.,
--CCN,--length,--min-duplicate-lines) in the hook args so that the pre-commit behavior is stable and aligned with your team’s agreed duplication and complexity limits.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider constraining the lizard hook to your actual source tree (e.g., `files` / `exclude` patterns) so that third-party, generated, or tooling scripts aren’t inadvertently scanned and cause noisy duplication/complexity findings.
- It may be helpful to explicitly set lizard thresholds (e.g., `--CCN`, `--length`, `--min-duplicate-lines`) in the hook args so that the pre-commit behavior is stable and aligned with your team’s agreed duplication and complexity limits.
## Individual Comments
### Comment 1
<location> `.pre-commit-config.yaml:37-40` </location>
<code_context>
- "--error-exitcode=0"
files: ^(src/latt|tests).*\.(c|h|cc|cpp)$
+
+ - repo: https://github.com/terryyin/lizard
+ rev: v1.17.13
+ hooks:
+ - id: lizard
+ args: ["--languages", "c,cpp,python"]
+
</code_context>
<issue_to_address>
**suggestion (performance):** Consider scoping the lizard hook to relevant paths to avoid slow pre-commit runs.
This hook currently has no `files` or `exclude` selector, so it will scan all matching languages across the repo. To keep runs fast and avoid analyzing vendored/generated code, consider adding a `files` pattern (e.g. `^(src|lib|app|tests)/`) and/or `exclude` for third-party directories.
Suggested implementation:
```
- repo: https://github.com/terryyin/lizard
rev: v1.17.13
hooks:
- id: lizard
args: ["--languages", "c,cpp,python"]
files: "^(src|lib|app|tests)/"
exclude: "^(third_party|vendor|build|dist|.venv)/"
```
If your repository uses different top-level directories (e.g. `src/latt` as in the cppcheck hook), you may want to adjust the `files` pattern to better reflect your actual layout, for example: `files: "^(src/latt|tests)/"`. Similarly, tune the `exclude` pattern to match any specific generated or vendored directories present in your project.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| - repo: https://github.com/terryyin/lizard | ||
| rev: v1.17.13 | ||
| hooks: | ||
| - id: lizard |
There was a problem hiding this comment.
suggestion (performance): Consider scoping the lizard hook to relevant paths to avoid slow pre-commit runs.
This hook currently has no files or exclude selector, so it will scan all matching languages across the repo. To keep runs fast and avoid analyzing vendored/generated code, consider adding a files pattern (e.g. ^(src|lib|app|tests)/) and/or exclude for third-party directories.
Suggested implementation:
- repo: https://github.com/terryyin/lizard
rev: v1.17.13
hooks:
- id: lizard
args: ["--languages", "c,cpp,python"]
files: "^(src|lib|app|tests)/"
exclude: "^(third_party|vendor|build|dist|.venv)/"
If your repository uses different top-level directories (e.g. src/latt as in the cppcheck hook), you may want to adjust the files pattern to better reflect your actual layout, for example: files: "^(src/latt|tests)/". Similarly, tune the exclude pattern to match any specific generated or vendored directories present in your project.
Codacy's Analysis Summary0 new issue (≤ 0 issue) Review Pull Request in Codacy →
|
|



Added
lizardpre-commit hook to detect code duplication and complexity issues in C, C++, and Python files.Resolves #79.
Summary by Sourcery
Build: