Skip to content

Report complexity#10

Merged
b4prog merged 11 commits into
mainfrom
report-complexity
Jun 28, 2026
Merged

Report complexity#10
b4prog merged 11 commits into
mainfrom
report-complexity

Conversation

@b4prog

@b4prog b4prog commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added a new --report-complexity mode with configurable cognitive and cyclomatic complexity thresholds.
    • Updated help and README with expanded examples for file selection (including -files quoting tips), git-branch workflows, and PowerShell-friendly usage.
    • Complexity output includes analyzed-file counts, timing breakdowns (when verbose), and functions exceeding the configured limits.
  • Bug Fixes
    • Improved CLI validation and input normalization, including stricter handling of incompatible options and unsupported inputs.
    • Updated exit behavior to return a non-zero status when issues are detected.
  • Chores
    • Bumped the release version to 0.7.3.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@b4prog, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 31 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0be89f4d-04b8-4030-b4e3-fa83c70c759a

📥 Commits

Reviewing files that changed from the base of the PR and between 36d1b9d and cbdd8de.

📒 Files selected for processing (1)
  • src/lib.rs
📝 Walkthrough

Walkthrough

Adds a --report-complexity mode to CodeM8 using rust-code-analysis. It introduces complexity data models, parallel detection and rendering, updated CLI/report routing, RunStatus-based exit handling, and refactors duplicate detection, rendering, and explicit-file discovery helpers.

Changes

Complexity Reporting Feature

Layer / File(s) Summary
Data model and CLI config contracts
src/model.rs, src/report/complexity_renderer.rs, src/cli/mod.rs, Cargo.toml
FunctionComplexity, ComplexityReport, and ComplexityReportTimings are added; ReportKind replaces the boolean report selector in CliConfig; CliCommand now uses a general Report(CliConfig) variant; the crate version is bumped and rust-code-analysis is added.
CLI parsing, validation, and help text
src/cli/args.rs, src/cli/help.rs, README.md
Adds --report-complexity and complexity threshold flags, mutual-exclusion validation, normalized argument handling, and PowerShell split-extension recovery. Help text and README usage/docs are updated for the new mode, thresholds, and exit behavior.
Complexity detection pipeline
src/report/complexity_detection.rs
Filters supported extensions, analyzes source files in parallel with rust-code-analysis, traverses function spaces to collect FunctionComplexity records, sorts results deterministically, and adds tests.
Complexity report rendering
src/report/complexity_renderer.rs, src/report/mod.rs
Renders the complexity report header, analyzed-file list, timings, and per-function details; adds metric/duration/extension formatting helpers; wires the new module into report exports.
Run dispatch, status, and exit codes
src/lib.rs, src/main.rs
run() returns RunStatus, routes help and report modes through the generalized command, gates analyzed-file output on verbosity, and main.rs converts status into process exit codes. Tests cover duplicate and complexity status outcomes.
Duplicate detection and renderer refactors
src/report/duplicate_detection.rs, src/report/duplicate_renderer.rs
Duplicate detection is split into helper stages for indexing, candidate generation, overlap handling, and block materialization; duplicate rendering is split into summary, block, verbose, and location helpers.
Explicit file discovery refactor
src/discovery/explicit.rs
Explicit-file discovery now uses helper functions for input resolution, metadata validation, and display-path generation, with a missing-path test added.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • b4prog/CodeM8#1: Introduced the original duplicate-report pipeline that this PR generalizes and refactors in src/lib.rs, src/report/duplicate_detection.rs, and src/report/duplicate_renderer.rs.
  • b4prog/CodeM8#2: Added verbose/timing handling for duplicate reporting, which this PR reworks in the duplicate renderer and mirrors in the new complexity report renderer.
  • b4prog/CodeM8#7: Changed module wiring around explicit discovery/report code paths, matching the helper extraction in src/discovery/explicit.rs and report module exports here.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.87% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding complexity reporting support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch report-complexity

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.

@b4prog b4prog marked this pull request as ready for review June 28, 2026 08:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/help.rs`:
- Around line 48-49: The help text for the -verbose flag is too broad because
render_complexity_report always shows the complexity metrics, so update the
wording in the help/README to describe only the fields that are actually
verbose-only, such as analyzed files and timings. Adjust the help string in the
CLI help definition and keep any related documentation wording aligned with the
same intent.

In `@src/discovery/explicit.rs`:
- Around line 48-54: In explicit_file_metadata, the symlink_metadata error
handling currently converts every failure into the missing-file message, which
hides real I/O causes. Update the map_err logic to match on the io::ErrorKind:
keep the existing “explicit file does not exist” CodeM8Error for NotFound, and
for all other errors wrap them with CodeM8Error::io so permission and path
failures are preserved.

In `@src/lib.rs`:
- Around line 80-92: Filter `-git-branch` paths before calling
`line::process_source_files` so branch-scoped scans only process changed files
instead of the full discovered set. In `src/lib.rs`, use the existing
`git_branch_files` and `filtered_processed_files` flow earlier in the
`discover_report_files`/`time_result` sequence so `process_source_files`
receives the narrowed file list, while keeping the existing
`duplicate_source_files` handling consistent.

In `@src/report/complexity_detection.rs`:
- Around line 160-179: The detects_functions_over_either_limit test in
complexity_detection.rs only exercises the case where both cognitive and
cyclomatic complexity exceed the threshold, so it does not prove the “either
limit” behavior. Update this test around detect_complex_functions and the risky
function fixture to add asymmetric coverage: one case where only
cognitive_complexity is over the limit and another where only
cyclomatic_complexity is over the limit, while keeping the assertions aligned
with the expected single-match result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e304bb8f-0cf4-4f03-b69e-7145233a143c

📥 Commits

Reviewing files that changed from the base of the PR and between f713a79 and 7842552.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • Cargo.toml
  • README.md
  • src/cli/args.rs
  • src/cli/help.rs
  • src/cli/mod.rs
  • src/discovery/explicit.rs
  • src/lib.rs
  • src/main.rs
  • src/model.rs
  • src/report/complexity_detection.rs
  • src/report/complexity_renderer.rs
  • src/report/duplicate_detection.rs
  • src/report/duplicate_renderer.rs
  • src/report/mod.rs
📜 Review details
🔇 Additional comments (12)
src/report/complexity_detection.rs (2)

13-37: LGTM!

Also applies to: 63-123, 149-157


49-50: 🎯 Functional Correctness

Don't silently treat parser failures as "no issues".

run_complexity_report in src/lib.rs:118-161 counts the file as analyzed before detection, so this Ok(Vec::new()) path can become a false negative if rust_code_analysis::get_function_spaces() returns None for invalid or unsupported syntax. Please verify the rust-code-analysis 0.0.25 contract here and either surface an error or report the file as skipped explicitly.

src/report/mod.rs (1)

1-11: LGTM!

src/model.rs (1)

45-53: LGTM!

src/report/complexity_renderer.rs (1)

8-130: LGTM!

Also applies to: 139-208

src/cli/mod.rs (1)

15-32: LGTM!

Also applies to: 50-50

Cargo.toml (1)

3-3: LGTM!

Also applies to: 17-17

src/cli/args.rs (1)

5-278: LGTM!

Also applies to: 281-506

src/cli/help.rs (1)

10-46: LGTM!

Also applies to: 51-122

src/main.rs (1)

17-23: LGTM!

src/report/duplicate_detection.rs (1)

22-33: LGTM!

Also applies to: 50-141, 177-265

src/report/duplicate_renderer.rs (1)

27-125: LGTM!

Comment thread src/cli/help.rs Outdated
Comment thread src/discovery/explicit.rs
Comment thread src/lib.rs
Comment thread src/report/complexity_detection.rs Outdated
@b4prog

b4prog commented Jun 28, 2026

Copy link
Copy Markdown
Owner Author

@CodeRabbit resume

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews resumed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib.rs`:
- Around line 84-88: `filtered_processed_files(...)` is dropping unchanged files
in `-git-branch` mode, which causes `detect_duplicate_blocks(...)` to miss
repo-wide duplicates. Update the `config.git_branch` branch in `src/lib.rs` so
the `processed_files` set is passed through unchanged instead of returning only
`config.files.as_deref()`, keeping duplicate detection full-repository. Refer to
the `filtered_processed_files` flow and the `detect_duplicate_blocks` call site
to make sure unchanged files remain included when `git_branch` is enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 819ecd08-6b67-4506-aeb1-8c42eb7ab8ce

📥 Commits

Reviewing files that changed from the base of the PR and between 7842552 and 36d1b9d.

📒 Files selected for processing (4)
  • src/cli/help.rs
  • src/discovery/explicit.rs
  • src/lib.rs
  • src/report/complexity_detection.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cli/help.rs
  • src/discovery/explicit.rs
📜 Review details
🔇 Additional comments (3)
src/report/complexity_detection.rs (1)

161-208: LGTM!

src/lib.rs (2)

128-132: LGTM!

Also applies to: 179-179


363-372: LGTM!

Also applies to: 418-425, 466-472, 497-509, 641-678

Comment thread src/lib.rs
@b4prog b4prog merged commit cbe4028 into main Jun 28, 2026
3 checks passed
@b4prog b4prog deleted the report-complexity branch June 28, 2026 11:00
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.

1 participant