Skip to content

Add code duplication detection to pre-commit#80

Open
Liam-Deacon wants to merge 1 commit intomasterfrom
chore/add-duplication-check
Open

Add code duplication detection to pre-commit#80
Liam-Deacon wants to merge 1 commit intomasterfrom
chore/add-duplication-check

Conversation

@Liam-Deacon
Copy link
Owner

@Liam-Deacon Liam-Deacon commented Jan 9, 2026

Added lizard pre-commit hook to detect code duplication and complexity issues in C, C++, and Python files.

Resolves #79.

Summary by Sourcery

Build:

  • Configure lizard pre-commit hook for C, C++, and Python sources.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Configures 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 hook

flowchart 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]
Loading

File-Level Changes

Change Details Files
Add lizard-based code duplication and complexity checks to the pre-commit configuration.
  • Register a new pre-commit repo pointing to terryyin/lizard at version v1.17.13.
  • Enable the lizard hook with default behavior and explicit language selection.
  • Configure the hook to analyze C, C++, and Python source files by passing the --languages argument.
.pre-commit-config.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#79 Add a code duplication checker for C/C++ (and compatible languages) to the .pre-commit-config.yaml configuration.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 1a5965c and 1e1b6d5.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +37 to +40
- repo: https://github.com/terryyin/lizard
rev: v1.17.13
hooks:
- id: lizard
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Codacy's Analysis Summary

0 new issue (≤ 0 issue)
0 new security issue

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2026

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.

Add code duplication check to pre-commit

1 participant