Skip to content

refactor(cli): reduce _output_and_exit cognitive complexity#179

Merged
Alberto-Codes merged 4 commits intomainfrom
refactor/cli-reduce-output-and-exit-cc
Feb 27, 2026
Merged

refactor(cli): reduce _output_and_exit cognitive complexity#179
Alberto-Codes merged 4 commits intomainfrom
refactor/cli-reduce-output-and-exit-cc

Conversation

@Alberto-Codes
Copy link
Owner

SonarQube flagged _output_and_exit() at cognitive complexity 17
(threshold 15, target ≤12) after the JSON format branch in #177.
Two changes, no behavior change.

  • Extract _emit_findings() helper for format dispatch (~5 CC reduction)
  • Collapse 3-branch format resolution to explicit identity-check ternary (~2 CC reduction)
  • Update docstrings for both functions to reflect new structure

Test: uv run pytest tests/unit/test_cli.py::TestOutputAndExit -v

Closes #178


PR Review

Checklist

  • Self-reviewed my code
  • Tests pass (uv run pytest)
  • Lint passes (uv run ruff check .)
  • Types pass (uv run ty check)
  • Breaking changes use ! in title and BREAKING CHANGE: in body

Review Focus

Verify the ternary at line 333 preserves exact semantics of the original if/elif/else. The is not None identity check (not truthiness) was chosen to match the original contract.

Related

…lexity

SonarQube flagged _output_and_exit at CC 17 (threshold 15, target ≤12)
after the JSON format branch in #177. Two changes, no behavior change:
collapse 3-branch format resolution to ternary, extract _emit_findings
helper for the format dispatch block.

Closes #178
Address two adversarial review findings: use explicit `is not None`
instead of truthiness for format resolution (F1), and clarify
_emit_findings docstring about empty-findings behavior (F3).
@Alberto-Codes Alberto-Codes marked this pull request as ready for review February 27, 2026 22:01
Copilot AI review requested due to automatic review settings February 27, 2026 22:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the CLI output pipeline to reduce SonarQube-reported cognitive complexity in _output_and_exit() while aiming to preserve behavior, following the introduction of the JSON output path in #177.

Changes:

  • Extract output dispatch into a new private helper _emit_findings().
  • Simplify output format resolution into a single expression.
  • Update docstrings to reflect the new structure and responsibilities.

Apply the same `is not None` identity check to `output_path` that was
already applied to `fmt_opt`, preserving exact original semantics for
both branches of the format resolution ternary.
@Alberto-Codes Alberto-Codes merged commit 40c86db into main Feb 27, 2026
12 checks passed
@Alberto-Codes Alberto-Codes deleted the refactor/cli-reduce-output-and-exit-cc branch February 27, 2026 22:07
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

refactor(cli): reduce _output_and_exit cognitive complexity from 17 to ≤12

3 participants