grokkit/internal/linter/language.go
Greg Gauthier fd033b03c7 fix(analyze): correct config, logger, and git usage in analyze command
- Fix config.GetModel to use command name and flag
- Switch to package-level logger functions
- Update git.IsRepo to take no arguments
- Simplify linter language detection comments
- Adjust Grok client creation to NewClient().StreamSilent
- Add error handling for confirmation input
- Remove unnecessary imports and refine comments in linter
2026-03-28 13:16:31 +00:00

52 lines
1.1 KiB
Go

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".
func DetectPrimaryLanguage(files []string) string {
if len(files) == 0 {
return "unknown"
}
counts := make(map[string]int)
for _, file := range files {
lang, err := DetectLanguage(file)
if err == nil && lang != nil {
name := strings.ToLower(lang.Name)
counts[name]++
}
}
if len(counts) == 0 {
return "unknown"
}
// Find most common language
var bestLang string
maxCount := -1
for lang, count := range counts {
if count > maxCount {
maxCount = count
bestLang = lang
}
}
// Bias toward Go in mixed repos
if counts["go"] > 0 && counts["go"] >= maxCount/2 {
return "go"
}
return bestLang
}
// SupportedLanguages returns all known languages (for future use or error messages).
func SupportedLanguages() []string {
var langs []string
for _, l := range languages {
langs = append(langs, strings.ToLower(l.Name))
}
return langs
}