package linter import ( "path/filepath" "strings" ) // DetectPrimaryLanguage returns the dominant language in the given list of files. // It counts occurrences of each detected language 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 the language with the highest count var bestLang string maxCount := -1 for lang, count := range counts { if count > maxCount { maxCount = count bestLang = lang } } // Friendly bias toward Go in mixed repos (common case) if counts["go"] > 0 && counts["go"] >= maxCount/2 { return "go" } return bestLang } // SupportedLanguages returns a list of all languages known to the linter. // Useful for error messages or future prompt discovery. func SupportedLanguages() []string { var langs []string for _, l := range languages { langs = append(langs, strings.ToLower(l.Name)) } return langs }