Skip to content

refactor(cli): reduce option parser cognitive complexity - #93

Merged
rodri-oliveira-dev merged 2 commits into
mainfrom
refactor/sonar-cli-parser-76
Oct 8, 2026
Merged

rodri-oliveira-dev merged 2 commits into
mainfrom
refactor/sonar-cli-parser-76

Conversation

@rodri-oliveira-dev

Copy link
Copy Markdown
Owner

Summary

Closes #76 — reduce ToolOptions.TryParse cognitive complexity (Sonar S3776, previously 52 against a limit of 15), retaining the CLI's existing behavior.

The parsing loop delegates to TryParseOption, which dispatches to three small private helpers based on the existing switch cases:

  • TryParseReportOption — --format and --output.
  • TryParseDuplicateOption — min/max duplicate thresholds and implicit duplicate detection.
  • TryParseComplexityOption — supported complexity and metric thresholds.

No parser library, public API change, option rename, or altered validation policy is introduced. The original switch case bodies have been moved without changing their assignment, validation, value-consumption, or error-handling logic.

Regression coverage

  • All supported CLI switches remain covered by Tool_options_parse_all_supported_switches.
  • New tests verify default settings and path normalization, last-value-wins semantics for repeated switches, and auto-enabling duplicate detection.
  • New parameterized tests cover missing values for all 14 value-taking switches and exact error messages for 12 invalid values (including zero, negatives, NaN and integer overflow).
  • Validate that parsing stops at the first unknown option with the exact original error.

Validation

The branch was created from the updated main (following merge of PR #92). Do not merge until CI and Sonar complete. The issue will be closed automatically when this PR is merged.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

SonarQube Cloud success

The SonarQube Cloud Quality Gate passed for this PR.

Quality Gate status: OK

Metric Status Actual Threshold
new_reliability_rating OK 1 1
new_security_rating OK 1 1
new_maintainability_rating OK 1 1
new_coverage OK 95.5 80
new_duplicated_lines_density OK 0.0 3
new_security_hotspots_reviewed OK 100.0 100

@rodri-oliveira-dev
rodri-oliveira-dev merged commit b94bc21 into main Oct 8, 2026
24 checks passed
@rodri-oliveira-dev
rodri-oliveira-dev deleted the refactor/sonar-cli-parser-76 branch October 8, 2026 17:12
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.

[Sonar][HIGH][MAINTAINABILITY] Cognitive Complexity of methods should not be too high

1 participant