This commit is contained in:
Tomas Dvorak
2026-02-22 15:41:27 +01:00
parent 0b88627e54
commit 409acd2e08
84 changed files with 65382 additions and 27475 deletions
@@ -268,7 +268,7 @@ type CouplingDetector struct {
func NewCouplingDetector(finder quality.FileFinder) *CouplingDetector {
return &CouplingDetector{
BaseDetector: quality.NewBaseDetector("coupling", quality.SeverityT3, finder),
maxFanOut: 10,
maxFanOut: 20, // Increased from 10 to 20 for more realistic threshold
}
}
@@ -330,7 +330,11 @@ func (d *CouplingDetector) Detect(ctx context.Context, path string, config *qual
for pkg, importedBy := range pkgImportedBy {
fanIn := len(importedBy)
if fanIn > d.maxFanOut*2 {
// Skip standard library packages from fan-in analysis
if d.isStandardLibraryPackage(pkg) {
continue
}
if fanIn > d.maxFanOut*3 { // Increased threshold for fan-in
finding := quality.Finding{
ID: fmt.Sprintf("coupling_fanin::%s", pkg),
Type: "coupling",
@@ -339,7 +343,7 @@ func (d *CouplingDetector) Detect(ctx context.Context, path string, config *qual
File: pkg,
Line: 1,
Severity: quality.SeverityT2,
Score: fanIn/5 - d.maxFanOut/5,
Score: fanIn/10 - d.maxFanOut/10, // Reduced scoring
Status: quality.StatusOpen,
Metadata: map[string]string{
"package": pkg,
@@ -356,6 +360,21 @@ func (d *CouplingDetector) Detect(ctx context.Context, path string, config *qual
return findings, nil
}
func (d *CouplingDetector) isStandardLibraryPackage(pkgPath string) bool {
// Standard library packages that commonly have high fan-in
standardLibs := []string{
"fmt", "time", "strings", "context", "os", "io", "net/http",
"encoding/json", "path/filepath", "sync", "math", "regexp",
}
for _, lib := range standardLibs {
if strings.Contains(pkgPath, lib) && !strings.Contains(pkgPath, "github.com") {
return true
}
}
return false
}
func (d *CouplingDetector) detectHubPackages(pkgImports, pkgImportedBy map[string][]string) []quality.Finding {
var findings []quality.Finding