mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 04:23:02 +00:00
update
This commit is contained in:
@@ -172,8 +172,7 @@ func (d *UnusedImportDetector) analyzeFile(path string) ([]quality.Finding, erro
|
||||
if imp.Name != nil {
|
||||
name = imp.Name.Name
|
||||
} else {
|
||||
parts := strings.Split(pkgPath, "/")
|
||||
name = parts[len(parts)-1]
|
||||
name = inferImportName(pkgPath)
|
||||
}
|
||||
imports[pkgPath] = name
|
||||
}
|
||||
@@ -191,8 +190,7 @@ func (d *UnusedImportDetector) analyzeFile(path string) ([]quality.Finding, erro
|
||||
if imp.Name != nil {
|
||||
name = imp.Name.Name
|
||||
} else {
|
||||
parts := strings.Split(pkgPath, "/")
|
||||
name = parts[len(parts)-1]
|
||||
name = inferImportName(pkgPath)
|
||||
}
|
||||
|
||||
if name == "_" || name == "." {
|
||||
@@ -224,6 +222,42 @@ func (d *UnusedImportDetector) analyzeFile(path string) ([]quality.Finding, erro
|
||||
return findings, nil
|
||||
}
|
||||
|
||||
func inferImportName(pkgPath string) string {
|
||||
parts := strings.Split(pkgPath, "/")
|
||||
if len(parts) == 0 {
|
||||
return pkgPath
|
||||
}
|
||||
|
||||
last := parts[len(parts)-1]
|
||||
if isSemverSegment(last) && len(parts) >= 2 {
|
||||
last = parts[len(parts)-2]
|
||||
}
|
||||
if idx := strings.Index(last, ".v"); idx > 0 && isDigits(last[idx+2:]) {
|
||||
last = last[:idx]
|
||||
}
|
||||
|
||||
return last
|
||||
}
|
||||
|
||||
func isSemverSegment(segment string) bool {
|
||||
if len(segment) < 2 || segment[0] != 'v' {
|
||||
return false
|
||||
}
|
||||
return isDigits(segment[1:])
|
||||
}
|
||||
|
||||
func isDigits(value string) bool {
|
||||
if value == "" {
|
||||
return false
|
||||
}
|
||||
for _, r := range value {
|
||||
if r < '0' || r > '9' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type CycleDetector struct {
|
||||
*quality.BaseDetector
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user