Skip to content

6.0.0

Choose a tag to compare

@rohaquinlop rohaquinlop released this 26 Jun 23:04
· 128 commits to main since this release

What's Changed

This major release brings the cognitive complexity algorithm into full conformance with the SonarSource white paper (v1.7), correcting several long-standing divergences from the specification. The fix touches every match, try/except, with, comprehension, lambda, and recursive call in every analyzed file, so all users should expect score changes across their codebases. The module structure has also been refactored to separate algorithm logic from path orchestration, improving maintainability and fixing a pre-existing wasm build failure.

Breaking Changes

All of the following correct algorithm behaviour that diverged from the SonarSource specification. After upgrading, you will see different cognitive complexity scores for any file using these constructs. In most cases scores will increase, reflecting previously missed complexity.

Migration: Re-run complexipy on your codebase after upgrading and review the new scores. If you use --max-complexity / --failed in CI, you will likely need to raise thresholds to accommodate the corrected scores. We recommend running in --quiet mode first to see the overall delta before tightening thresholds again.

  • match statements — now correctly apply a structural + nesting increment (B1/B2/B3) per the paper, instead of being scored as 0 (#192)
  • try/else/finally blocks — body collected at current nesting level instead of +1, matching the paper's rule that "try and finally blocks are ignored altogether" (#192)
  • except handlers — now charge 1 + nesting_level (B3 nesting increment) instead of a flat +1 (#192)
  • with blocks — body no longer incorrectly raises the nesting level (#192)
  • Direct recursion — added scope-aware RecursionFinder visitor that emits +1 for each self-call, correctly skipping nested function/class definitions and lambdas to avoid false positives (#192)
  • Lambda expressions — added Expr::Lambda arm in boolean-op counting, recursing into the body at nesting_level + 1 (#192)
  • Comprehensions — added ListComp, SetComp, DictComp, and Generator arms; each generator charges 1 + nesting_level, each if filter charges +1 (#192)
  • Nested ternariesExpr::If branches now recurse at nesting_level + 1 so inner ternaries receive the correct nesting increment (#192)
  • for/while else clauses — collected at the loop's own nesting level, not +1 (#192)
  • Bare expression statements — added Stmt::Expr arm to count boolean ops in standalone expressions (e.g. foo(a and b)) (#192)
  • for iterable — added boolean-op counting on the iterable expression for parity with while (#192)

Changed

  • Module structure — extracted all path orchestration (file I/O, directory traversal, URL cloning) from cognitive_complexity.rs into a new src/runner.rs module, gated #[cfg(feature = "python")], which also resolves a pre-existing wasm build failure caused by python-only symbols leaking into the wasm feature (#192)
  • Internal helpers — extracted push_line, absorb, absorb_with_regions, finalize_region, count_line_bool_ops, loop_complexity, is_ignored, and analyze_function helpers to eliminate the repeated fold/push pattern across all statement arms (#192)
  • loop_complexity unification — unified structurally identical Stmt::For and Stmt::While handling into a single loop_complexity call (#192)
  • Collapsed leaf arms — collapsed 7 near-identical statement arms (Assign, AnnAssign, AugAssign, Return, Raise, Assert, Expr) through count_line_bool_ops (#192)
  • Default on region types — derived Default on ComplexityRegion and RegionKind to eliminate repeated elif_count: 0, case_count: 0, ... noise across every structural arm (#192)
  • Removed merge_child — eliminated merge_child and its internal child.regions.clone() as regions never needed the double-propagation (#192)
  • Windows CI hardening — hardened the Windows release unit-test job against transient Cargo HTTP/2 framing layer failures by disabling multiplexing and increasing retries (#189)

Tests

  • Updated existing test assertions to match corrected scores: test_match (0→1), test_recursive (0→1), test_try_nested (12→10), directory totals adjusted accordingly (#192)
  • Added TestPaperConformance class with 14 targeted tests covering each fixed algorithm rule, including recursion regression tests for nested-function and lambda edge cases (#192)

Chores

  • Added [tool.uv] cache-keys to pyproject.toml to improve uv cache invalidation accuracy (#192)

PRs

  • fix(complexity): align cognitive complexity algorithm with SonarSource paper and refactor module structure by @rohaquinlop in #192
  • ci: Stabilize Windows release unit-test job by hardening Cargo network behavior by @copilot-swe-agent in #189

Full Changelog: 5.6.1...6.0.0