refactor(linter): clean language names in primary detection
All checks were successful
CI / Test (push) Successful in 26s
CI / Lint (push) Successful in 18s
CI / Build (push) Successful in 14s

Update DetectPrimaryLanguage to normalize "C/C++" and "C++" to "c" for consistent counting.
Revise function comment and internal comments for clarity.
Remove redundant comment on finding most common language.
This commit is contained in:
Greg Gauthier 2026-03-28 16:24:26 +00:00
parent 5cb84f44bb
commit 12bd5f9376

View File

@ -2,9 +2,7 @@ package linter
import "strings"
// DetectPrimaryLanguage returns the dominant language from the list of files.
// It counts detected languages and returns the most frequent one.
// Falls back to "go" (common default) or "unknown".
// DetectPrimaryLanguage returns a clean language name without slashes or special chars.
func DetectPrimaryLanguage(files []string) string {
if len(files) == 0 {
return "unknown"
@ -15,6 +13,10 @@ func DetectPrimaryLanguage(files []string) string {
lang, err := DetectLanguage(file)
if err == nil && lang != nil {
name := strings.ToLower(lang.Name)
// Clean the name: turn "C/C++" into "c"
if name == "c/c++" || name == "c++" {
name = "c"
}
counts[name]++
}
}
@ -23,7 +25,6 @@ func DetectPrimaryLanguage(files []string) string {
return "unknown"
}
// Find most common language
var bestLang string
maxCount := -1
for lang, count := range counts {
@ -33,7 +34,7 @@ func DetectPrimaryLanguage(files []string) string {
}
}
// Bias toward Go in mixed repos
// Bias toward Go in mixed repos, otherwise prefer "c" for C files
if counts["go"] > 0 && counts["go"] >= maxCount/2 {
return "go"
}