i dont like commits

This commit is contained in:
Tomas Dvorak
2026-02-24 12:10:13 +01:00
parent 898a3c303f
commit 1d72a1cc01
109 changed files with 43586 additions and 8484 deletions
@@ -239,7 +239,7 @@ func (d *SingleUseDetector) getFuncLOC(file string, startLine int) (int, error)
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, file, nil, 0)
if err != nil {
return 0, err
return 0, fmt.Errorf("parse %s for function loc lookup: %w", file, err)
}
loc := 0
@@ -43,6 +43,21 @@ func (d *LargeFileDetector) Detect(ctx context.Context, path string, config *qua
for _, file := range files {
loc, err := countLines(file)
if err != nil {
findings = append(findings, quality.Finding{
ID: fmt.Sprintf("detector_read_error::large_file::%s", file),
Type: "detector_error",
Title: "Large file detector could not read file",
Description: fmt.Sprintf("Failed to count lines in %s: %v", filepath.Base(file), err),
File: file,
Line: 1,
Severity: quality.SeverityT2,
Score: 0,
Status: quality.StatusOpen,
Metadata: map[string]string{
"detector": "large_file",
"error": err.Error(),
},
})
continue
}
@@ -99,18 +114,21 @@ func (d *GodStructDetector) Detect(ctx context.Context, path string, config *qua
var findings []quality.Finding
for _, file := range files {
fileFindings := d.analyzeFile(file)
fileFindings, err := d.analyzeFile(file)
if err != nil {
return nil, fmt.Errorf("analyze god struct in %q: %w", file, err)
}
findings = append(findings, fileFindings...)
}
return findings, nil
}
func (d *GodStructDetector) analyzeFile(path string) []quality.Finding {
func (d *GodStructDetector) analyzeFile(path string) ([]quality.Finding, error) {
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, path, nil, 0)
if err != nil {
return nil
return nil, fmt.Errorf("parse %s: %w", path, err)
}
methodCounts := make(map[string]int)
@@ -198,7 +216,7 @@ func (d *GodStructDetector) analyzeFile(path string) []quality.Finding {
}
}
return findings
return findings, nil
}
type DebugLogDetector struct {
@@ -227,22 +245,25 @@ func (d *DebugLogDetector) Detect(ctx context.Context, path string, config *qual
var findings []quality.Finding
for _, file := range files {
fileFindings := d.analyzeFile(file)
fileFindings, err := d.analyzeFile(file)
if err != nil {
return nil, fmt.Errorf("analyze debug logs in %q: %w", file, err)
}
findings = append(findings, fileFindings...)
}
return findings, nil
}
func (d *DebugLogDetector) analyzeFile(path string) []quality.Finding {
func (d *DebugLogDetector) analyzeFile(path string) ([]quality.Finding, error) {
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, path, nil, 0)
if err != nil {
return nil
return nil, fmt.Errorf("parse %s: %w", path, err)
}
normPath := filepath.ToSlash(path)
if strings.Contains(normPath, "internal/ui/") || strings.Contains(normPath, "examples/") {
return nil
return nil, nil
}
debugPatterns := []string{
@@ -324,7 +345,7 @@ func (d *DebugLogDetector) analyzeFile(path string) []quality.Finding {
return true
})
return findings
return findings, nil
}
type GodFunctionDetector struct {
@@ -37,7 +37,7 @@ func (d *TestCoverageDetector) Detect(ctx context.Context, path string, config *
_, err := exec.LookPath("go")
if err != nil {
return nil, nil
return nil, fmt.Errorf("go toolchain is not available: %w", err)
}
if _, err := os.Stat(coverFile); os.IsNotExist(err) {
@@ -48,13 +48,13 @@ func (d *TestCoverageDetector) Detect(ctx context.Context, path string, config *
}
if _, err := os.Stat(coverFile); os.IsNotExist(err) {
return nil, nil
return nil, fmt.Errorf("coverage profile was not generated at %q", coverFile)
}
}
coverage, err := d.parseCoverageFile(coverFile)
if err != nil {
return nil, err
return nil, fmt.Errorf("parse coverage profile %q: %w", coverFile, err)
}
var findings []quality.Finding
@@ -210,7 +210,7 @@ func (d *UntestedFuncDetector) Detect(ctx context.Context, path string, config *
coverFile := filepath.Join(path, "coverage.out")
data, err := os.ReadFile(coverFile)
if err != nil {
return nil, nil
return nil, fmt.Errorf("read coverage profile %q: %w", coverFile, err)
}
uncoveredFuncs := make(map[string][]UncoveredFunc)