cognitive_complexity 0.3.0
cognitive_complexity: ^0.3.0 copied to clipboard
Algorithmic Cognitive Complexity calculation and Data-Flow analysis library and CLI tools for Dart and Flutter.
0.3.0 #
- Breaking:
ShallowFindinggains two required constructor parameters,callerBaseScoreandcallerCumulativeBefore. Code that only reads findings fromShallowAnalyzeris unaffected; code constructingShallowFindingdirectly must pass both. shallow: when several single-caller helpers share one caller, the caller's score was reported as a running cumulative total with no way to recover the caller's real static score. Each finding now reportscaller_base_score(the caller's static score) alongsidecaller_cumulative_before(the simulated score after earlierSAFE_INLINEsiblings were absorbed).caller_scoreis retained as an alias ofcaller_cumulative_before. Text output rendersCaller CC: 6 (base 3) -> 9 after inline (+3)whenever the two differ.cognitive_complexity: with--max-function-lines, the text table and the--git-difftext table now include aLinescolumn, and every violation marker names its trigger, e.g.[VIOLATION: score > 15],[VIOLATION: lines > 60],[VIOLATION: score > 15, lines > 60], or[VIOLATION: increased]under--fail-on-increase. Consumers matching the bare[VIOLATION]token on stdout should match the[VIOLATIONprefix instead. JSON output is unchanged.
0.2.6 #
- Auto-discover default targets when no positional paths are given: Pub
workspace members (
<member>/lib), single-packagelib/, orpackages/*/lib/pkgs/*/libmonorepo layouts. The GitHub Actiontargetsinput now defaults to auto-discovery, so workspace and monorepo callers no longer need a hardcoded target list (#137). - Order
--git-diffdelta tables by review significance in every format (step summary, PR comment,text,json): violations first, then new score descending, then delta descending, then location.DeltaAnalyzer.computeDeltasgainsfailThreshold,maxFunctionLines, andfailOnIncreaseparameters and the comparator is exposed ascompareBySignificance(#53).
0.2.5 #
- Omit zero-complexity (
delta == 0,score == 0) added and removed declarations from--git-diffMarkdown, CLI, and JSON delta tables (unless they trigger--max-function-lines), addDeltaSummary.countRemoved(🗑️), and format added/removedScorecells as_new_ -> **N**andN -> _deleted_. - Add
shallowCLI (dart run cognitive_complexity:shallow) andShallowAnalyzer(ShallowReport,ShallowFinding,ShallowClassification) to detect single-caller shallow helpers (HIGH_ARITY,MICRO_HELPER,SIG_HEAVY,CROSS_FILE_SINGLE_CALLER) and simulate exact nesting-aware caller Cognitive Complexity after re-inlining (SAFE_INLINE,FLATTEN_AND_INLINE,LOAD_BEARING). - Enhance
DataFlowAnalyzerandDataFlowResult(cognitive_complexity:data_flow) with nesting-aware complexity impact metrics (enclosingScore,sliceScoreInPlace,sliceScoreAtRoot,estimatedEnclosingScoreAfter) andextractionWarningswhen a proposed slice requires>= 5input parameters or provides low complexity payoff. - Add opt-in
--max-file-linesand--max-function-linesCLI flags and GitHub Action inputs (max-file-lines,max-function-lines) with--git-diffpragmatic ratchet support (FileLineMetric,FileLineDelta). Disabled (null) by default to preserve full backward compatibility. - Support
// cognitive_complexity:ignore(per-declaration) and// cognitive_complexity:ignore_for_file(file-wide) suppression comment directives viaCommentDirectiveParser. - Add
file_splitCLI (dart run cognitive_complexity:file_split) andFileSplitAnalyzer(analyzeFile/analyzeFiles) to compute acyclic file decomposition cuts targeting coarse<= 800-line subsystems using Tarjan's SCC condensation, immediate dominator cone absorption, dynamic shared-tail diamond re-evaluation, one-shot sufficiency & surplus small-cut re-absorption, zero-crossing sibling cone coalescing,staticmethod promotion and embedded string/asset literal (>75%) detection for oversized classes, multi-file and directory batch execution,--[no-]use-partssupport, and zero-churnexport ... showbarrel generation. - Skip writing the
--comment-outputfile entirely when a run has zero violations and zero complexity increases, so the GitHub Action stays quiet on the PR thread instead of posting an all-zeroes summary comment. The full report still lands in$GITHUB_STEP_SUMMARY. A diff that only improves complexity now also stays quiet. - Add
DeltaSummary.isClean(), the predicate behind that decision. - GitHub Action: when a previously reported PR gets clean, the existing sticky
comment is updated in place to a resolved status (never deleted), and only
a successful run is treated as clean, so a crashed scan can no longer mark
stale findings resolved.
--comment-outputis only requested when the scanner runs ingithubformat against a diff base. - Support
--excludeand--[no-]ignore-generatedCLI options to configure file exclusion and generated code filtering viaPathFilter. - Add
pathFilterparameter toComplexityAnalyzerandDeltaAnalyzer. - Remove noisy GitHub workflow
::warningannotations on non-violating complexity increases, keeping inline annotations reserved for violations (::error) while full deltas remain tracked in step summaries and PR comment tables. - Add
ensure_cli_readme_test.dartto verify CLI--helpdocumentation inREADME.md. - Update GitHub Action documentation in
README.mdto reference modular subdirectory path (packages/cognitive_complexity) and add rendered Action Inputs Reference table.
0.2.4 #
- Fix
action.ymlmonorepo auto-detection to evaluate defaultlibvspackagesexistence against the caller's$GITHUB_WORKSPACEinstead of$ACTION_PATH(#76). - Fix
action.ymlto run the scanner from the caller's$GITHUB_WORKSPACErather than$ACTION_PATH, so relativetargetsand--git-diffresolve against the repository under audit when the action is used from another repository (#76). - Add
--comment-outputand--max-comment-rowsCLI options: with--format=github, write a second report capped to the most significant rows (violations, then increases, then additions) for posting as a PR comment, while the step summary keeps the full table (#49). - Add
commentFileandmaxCommentRowsparameters toGitHubReporter. - Add
max-comment-rowsinput to the GitHub Action (default0= unlimited) to keep sticky comments under GitHub's 65536-character body limit. - Anchor GitHub annotations to the declaration line only, so they render under the function signature instead of after the closing brace (#55).
- Move package into pub workspace monorepo layout under
packages/cognitive_complexity. - Restore root
action.ymlandskills/structure for monorepo workspace.
0.2.3 #
- Replace table truncation notice with inline summary comment linking to step summary.
0.2.2 #
- Fix column wrapping and alignment formatting in markdown report tables.
0.2.1 #
- Add support for GitHub Actions step summary and comment outputs.
0.2.0 #
- Add Data-Flow analysis and helper extraction engine.
0.1.0 #
- Initial release of Cognitive Complexity calculation engine and CLI tool.