Repository navigation
fix(analyzer): exclude isolated modules from coupling averages - #854
Open
TheNetherWatcher wants to merge 2 commits into
Open
TheNetherWatcher wants to merge 2 commits into
TheNetherWatcher wants to merge 2 commits into
Conversation
Modules with no in-project imports and no importers (Ca + Ce = 0) have undefined instability, which defaulted to 0 and produced Distance 1. They were averaged into MainSequenceDeviation and AverageInstability, marked high risk, and ranked as refactoring candidates, so a fully decoupled package scored worse than an import chain. Leave isolated modules out of the instability/distance averages and the instability variance used by SystemComplexity, skip the distance term in refactoring priority for them, and report them as low risk. Fixes ludo-technologies#850
This branch has not been deployed
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.
Summary
Modules with no in-project imports and no importers (Ca + Ce = 0) have undefined instability. It defaulted to 0, giving Distance 1, and those modules were averaged into MSD and average instability, marked
risk_level: high, and listed as refactoring candidates. A fully decoupled package scored worse than an import chain. This treats instability/distance as undefined for isolated modules, as proposed in the issue.Type of Change
Related Issues
Fixes #850
Changes
analyzer.IsIsolatedModule(Ca + Ce == 0).calculateSystemMetrics: leave isolated modules out ofMainSequenceDeviationandAverageInstability(both 0 when every module is isolated).AverageAbstractness, fan-in/out and dependency ratio are unchanged.calculateSystemComplexity: compute the instability variance over the same coupled modules, so it stays consistent with the newAverageInstability.identifyRefactoringPriorities: skip the distance term for isolated modules. Cycle and complexity terms still apply.system_analysis_service.go: isolated modules are alwaysRiskLevelLow, so they no longer count towardHighRiskModules.docs/algorithms/dependency.md: describe the new handling ofCa + Ce = 0.extract_metrics_with_high_riskfixture had Ca = Ce = 0, so I gave itAfferentCoupling: 3to keep testing the distance-based high-risk path.Out of scope, as the issue notes: modules with Ca > 0, Ce = 0 and no classes (D = 1) are unchanged.
Testing
make testpasses locally (go test -race ./...)make lintpasses locally (0 issues)internal/analyzer/coupling_metrics_test.go: all-isolated graph, and a mixed graph with one isolated module)pkg/__init__.pyplus 4 independent modules) with binaries built before and after the changedeps_main_sequence_deviationdependency_scorehealth_scorehigh_risk_modulesDocumentation
Additional Context
AI disclosure: this change was written with AI assistance (Claude). I reviewed the diff and ran the tests, lint and repro above locally.