refactor(linter): clean language names in primary detection
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:
parent
5cb84f44bb
commit
12bd5f9376
@ -2,9 +2,7 @@ package linter
|
|||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
// DetectPrimaryLanguage returns the dominant language from the list of files.
|
// DetectPrimaryLanguage returns a clean language name without slashes or special chars.
|
||||||
// It counts detected languages and returns the most frequent one.
|
|
||||||
// Falls back to "go" (common default) or "unknown".
|
|
||||||
func DetectPrimaryLanguage(files []string) string {
|
func DetectPrimaryLanguage(files []string) string {
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
@ -15,6 +13,10 @@ func DetectPrimaryLanguage(files []string) string {
|
|||||||
lang, err := DetectLanguage(file)
|
lang, err := DetectLanguage(file)
|
||||||
if err == nil && lang != nil {
|
if err == nil && lang != nil {
|
||||||
name := strings.ToLower(lang.Name)
|
name := strings.ToLower(lang.Name)
|
||||||
|
// Clean the name: turn "C/C++" into "c"
|
||||||
|
if name == "c/c++" || name == "c++" {
|
||||||
|
name = "c"
|
||||||
|
}
|
||||||
counts[name]++
|
counts[name]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,7 +25,6 @@ func DetectPrimaryLanguage(files []string) string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find most common language
|
|
||||||
var bestLang string
|
var bestLang string
|
||||||
maxCount := -1
|
maxCount := -1
|
||||||
for lang, count := range counts {
|
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 {
|
if counts["go"] > 0 && counts["go"] >= maxCount/2 {
|
||||||
return "go"
|
return "go"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user