chore: Add advisory code complexity checks#1402
Conversation
Introduce cyclop configuration for the Go CLI and a CA1502-based C# analysis host so complexity hotspots can be reported without editing Unity-generated project files. Wire the advisory check into CI and document threshold and fail-mode operation.
|
Warning Review limit reached
More reviews will be available in 5 minutes and 57 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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a code-complexity checker for Go and C# with shared models, Roslyn analysis, CLI output, shell execution, CI wiring, tests, and documentation. ChangesCode complexity toolchain
Sequence Diagram(s)sequenceDiagram
participant Program
participant CommandLineOptions
participant CodeComplexityAnalyzerRunner
participant CodeComplexityReporter
Program->>CommandLineOptions: HasHelpOption(args)
alt help requested
Program->>CommandLineOptions: CreateHelpText()
else run analysis
Program->>CommandLineOptions: Parse(args)
Program->>CodeComplexityAnalyzerRunner: AnalyzeAsync(options, ct)
Program->>CodeComplexityReporter: Write(issues, options)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
tests/UnityCliLoop.CodeComplexity.Tests/CodeComplexityAnalyzerRunnerTests.cs (1)
127-177: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtend the fixture to cover the remaining discovery rules.
CreateSampleRepository()only exercisesPackages/srcandAssets, so the new<root>/testspath and the/.agents///.claude/exclusions can regress silently.🤖 Prompt for 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. In `@tests/UnityCliLoop.CodeComplexity.Tests/CodeComplexityAnalyzerRunnerTests.cs` around lines 127 - 177, CreateSampleRepository only covers Packages/src and Assets, so add fixture content that also exercises the remaining discovery rules in CodeComplexityAnalyzerRunnerTests. Extend the sample repo setup to include a tests directory under the root and hidden .agents and .claude directories so the discovery logic is validated against both the new root/tests path and the exclusion filters. Keep the changes localized to CreateSampleRepository and use WriteFile to add representative files in those locations..github/workflows/code-complexity.yml (1)
47-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExercise the blocking-mode path somewhere in CI.
This workflow only covers advisory mode, so the documented non-zero exit behavior can drift unnoticed until someone enables
CODE_COMPLEXITY_FAIL_ON_EXCEEDED=truefor real. Add a small smoke test or fixture that is expected to fail in blocking mode.🤖 Prompt for 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. In @.github/workflows/code-complexity.yml around lines 47 - 61, The code-complexity workflow only runs advisory checks, so add a CI smoke check that explicitly exercises the blocking-mode path and expects a non-zero exit when complexity is exceeded. Update the existing code-complexity workflow around Report complexity / Write complexity artifacts to include a small fixture or temporary check that runs scripts/check-code-complexity.sh with CODE_COMPLEXITY_FAIL_ON_EXCEEDED=true and verifies failure, using the same complexity tooling paths already present.
🤖 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 `@tools/UnityCliLoop.CodeComplexity/CodeComplexityAnalyzerRunner.cs`:
- Around line 24-31: Expand the hardcoded DefaultPreprocessorSymbols in
CodeComplexityAnalyzerRunner so it includes all repository-used defines
currently missing from the analyzer: ULOOP_DEBUG, ULOOP_HAS_TEST_FRAMEWORK,
UNITY_6000_3_OR_NEWER, and UNITY_6000_4_OR_NEWER. Keep the existing symbol list
in the same static array and add these entries alongside the other Unity/ULOOP
symbols so conditional branches in the analyzer are parsed correctly.
In `@tools/UnityCliLoop.CodeComplexity/Program.cs`:
- Around line 19-37: The CLI entry point in RunAsync currently lets
CommandLineOptions.Parse throw and print a stack trace for invalid arguments.
Wrap the parse path in Program.RunAsync so expected validation failures are
caught, emit a clean usage/error message, and return a non-zero exit code, while
leaving CodeComplexityAnalyzerRunner.AnalyzeAsync and other unexpected
exceptions unhandled so real bugs still fail fast.
---
Nitpick comments:
In @.github/workflows/code-complexity.yml:
- Around line 47-61: The code-complexity workflow only runs advisory checks, so
add a CI smoke check that explicitly exercises the blocking-mode path and
expects a non-zero exit when complexity is exceeded. Update the existing
code-complexity workflow around Report complexity / Write complexity artifacts
to include a small fixture or temporary check that runs
scripts/check-code-complexity.sh with CODE_COMPLEXITY_FAIL_ON_EXCEEDED=true and
verifies failure, using the same complexity tooling paths already present.
In
`@tests/UnityCliLoop.CodeComplexity.Tests/CodeComplexityAnalyzerRunnerTests.cs`:
- Around line 127-177: CreateSampleRepository only covers Packages/src and
Assets, so add fixture content that also exercises the remaining discovery rules
in CodeComplexityAnalyzerRunnerTests. Extend the sample repo setup to include a
tests directory under the root and hidden .agents and .claude directories so the
discovery logic is validated against both the new root/tests path and the
exclusion filters. Keep the changes localized to CreateSampleRepository and use
WriteFile to add representative files in those locations.
🪄 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: 69719729-887a-47e5-a8a8-5b4594451f10
⛔ Files ignored due to path filters (3)
tests/UnityCliLoop.CodeComplexity.Tests/UnityCliLoop.CodeComplexity.Tests.csprojis excluded by none and included by nonetools/UnityCliLoop.CodeComplexity/CodeMetricsConfig.txtis excluded by none and included by nonetools/UnityCliLoop.CodeComplexity/UnityCliLoop.CodeComplexity.csprojis excluded by none and included by none
📒 Files selected for processing (12)
.github/workflows/code-complexity.ymlcli/.golangci-complexity.ymldocs/code-complexity.mdscripts/check-code-complexity.shtests/UnityCliLoop.CodeComplexity.Tests/CodeComplexityAnalyzerRunnerTests.cstools/UnityCliLoop.CodeComplexity/CodeComplexityAnalyzerRunner.cstools/UnityCliLoop.CodeComplexity/CodeComplexityModels.cstools/UnityCliLoop.CodeComplexity/CodeComplexityReporter.cstools/UnityCliLoop.CodeComplexity/CodeMetricsAdditionalText.cstools/UnityCliLoop.CodeComplexity/CommandLineOptions.cstools/UnityCliLoop.CodeComplexity/Program.cstools/UnityCliLoop.CodeComplexity/SourceFileCollector.cs
There was a problem hiding this comment.
5 issues found across 15 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Keep advisory complexity reporting robust by preserving real golangci-lint failures, broadening the C# analyzer preprocessor context, and returning clean validation failures for expected CLI input errors.
There was a problem hiding this comment.
1 issue found across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Reject malformed --root values before calling Path.GetFullPath so expected command-line validation failures keep returning a deterministic parse result instead of an unhandled exception.
Summary
User Impact
Changes
cyclopat threshold 25.Verification
dotnet test tests/UnityCliLoop.CodeComplexity.Tests/UnityCliLoop.CodeComplexity.Tests.csproj --configuration Releasedotnet test tests/UnityCliLoop.DeadCodeScanner.Tests/UnityCliLoop.DeadCodeScanner.Tests.csproj --configuration Releasescripts/check-go-cli.shscripts/check-code-complexity.shCODE_COMPLEXITY_FAIL_ON_EXCEEDED=true scripts/check-code-complexity.shexits non-zero with the current advisory findings, as expected.autoreview --mode branch --base origin/v3-betareported no accepted/actionable findings.