mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-03 20:13:03 +00:00
updage
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user