Repository navigation
Reduce cognitive complexity to <= 15 and de-duplicate web UI export - #196
Merged
Merged
Conversation
- Reduce all 11 functions above cognitive complexity 15 into the 8-15 target zone across `dot.dart`, `executable.dart`, `terminate.dart`, `update_order.dart`, `graph_renderer.dart`, and `ui_manager.dart`. - Re-inline single-caller `SAFE_INLINE` micro-helpers and group shared parameter clumps into private records in `mermaid.dart` and `service.dart`. - Rebuild embedded web assets (`lib/src/assets.g.dart`) via `dart tool/update_assets.dart`.
📊 Cognitive Complexity AnalysisNet Delta: -116 | Added: 15 | Increased: 1 | Improved: 12 | Removed: 3 | Violations: 0
|
- service.dart: restore _loadPackageGraphFile, _loadPackageConfigFile, _loadPubspecForPackage, _resolvePrimaryVersion; drop the _PrimaryBuildContext record and return _buildPrimaryPackage to named params - viz_root.dart: restore _filterIgnored, _filterStandard, _filterIsolated so every filter() pipeline step is a named method - ui_manager.dart: share the controls toast via _toggleControls and _showControlsToast; make the unreachable png case throw StateError - pubviz.dart: restore _indent - mermaid.dart: pass rootName/isWorkspace to _writeNode instead of VizRoot
- ui_manager.dart: dispatch all export formats in one exhaustive switch; dot/mermaid/svg share _exportText, svg/png share _graphSvg, so the unreachable png arm is gone. Toasts, filenames, and MIME types are unchanged. - mermaid.dart: replace the six-list _MermaidStyleLists record with a _MermaidStyles class (addNode/addEdge/write). Output is byte-identical.
kevmoo
added a commit
to kevmoo/analytica.dart
that referenced
this pull request
Oct 9, 2026
…184) The `dart-cognitive-complexity` skill pushes agents to clear every `shallow` and `file_split` finding, which caused over-refactoring and regressions in dogfood runs. ## Changes - **Stop rule:** only declarations above the threshold are work items. When max CC <= threshold, report done and stop; anything further needs a user ask. - **Advisory, not gates:** `shallow` and `file_split` are documented as optional review aids. Removed the "batch re-inline SAFE_INLINE" triage option and every `--fail-on-safe-inline` gate recommendation. The findings-table action now reads "Review: consider re-inlining if ...". - **Keep/revert heuristics (new §5.3):** keep de-duplication, guard clauses, and named step helpers. Don't inline helpers with same-shape siblings or meaningful names/docs, don't make style-only edits, and don't split files without a cohesive name (no barrels or cycles). - **Hot-loop rule (new §5.4):** benchmark before splitting per-element kernels. Prefer an inline kernel with `// cognitive_complexity:ignore` on the line before the declaration, plus a reason comment. - **Blind self-review:** for diffs over ~300 lines, a fresh agent or human reviewer given only the before/after trees and diff judges each change. - **`refactoring_recipes.md`:** Pattern G no longer says "always re-inline". Pattern F now says to name split files by their contents. - **Evals:** replaced the shallow-gate assertion and added negative assertions (no batch re-inline, sibling helpers stay extracted, no style-only edits). Added `complexity_stop_when_clean`. Docs-only: no version, pin, or CHANGELOG changes. ## Evidence Blind reviews of the dogfood PRs found that fixing CC > 15 helped, but re-inlining `SAFE_INLINE` helpers and name-by-one-function file splits mostly hurt: - kevmoo/qr.dart#174, kevmoo/dash_skills#59, kevmoo/pubviz#196, kevmoo/scripts.dart#147 - kevmoo/qr.dart#175 restored an inline hot kernel after the helper split made generation 39-66% slower on AOT Related (not fixed here): #181, #183
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
graph_renderer.dart:_updateOver38 -> 13,_renderWithWorker29 -> 10,_updateBody26 -> 7executable.dart:run29 -> 8terminate.dart:waitForTerminate26 -> 14ui_manager.dart:UIManagerconstructor 25 -> 10,_exportPng23 -> 6,_injectStyles19 -> 15,_exportAction17 -> 8update_order.dart:computeUpdateOrder16 -> 14dot.dart:_writeDot(34) removed; logic now lives intoDotplus_nodeProperties/_edgeProperties_exportText), driven bylabel/extension/contentTypeon_ExportFormat; svg and png share_graphSvg. Toasts, filenames and MIME types are unchanged._toggleControls/_showControlsToastreplace the duplicated "Controls Shown/Hidden" toast._GraphNode/_GraphEdgetypedefs,classList.toggle,_onWorkerMessage, and reuse ofVizPackage.isOutdated.executable.dart: extract_resolveLocalPathand_printUpdateOrder; remove the unused_printContent/_getContentDot.mermaid.dart: a small_MermaidStylesclass owns the node and link style lists (addNode/addEdge/write). Output is byte-identical (checked on this package andtest/demo_workspace).lib/src/assets.g.dart) viadart tool/update_assets.dart.Gates:
dart format,dart analyze --fatal-infos,dart test,dart test -P presubmit,api_summary --check(no API change),cognitive_complexity --fail-threshold 15(max 15),--git-diff origin/main --fail-on-increase(0 violations, net delta -116), andkscripts pr-check.