LanguagesByFilename: fix language order in generated code

Otherwise, generator tests are flaky

test plan
 * make code-generate
 * go test -run '^TestGetLanguagesByFilename$' github.com/go-enry/go-enry/v2
This commit is contained in:
Alex Bezzubov 2023-09-22 14:58:53 +02:00
parent bd3630419c
commit dc1110e30c
2 changed files with 7 additions and 3 deletions

View File

@ -157,7 +157,7 @@ var LanguagesByFilename = map[string][]string{
"Gemfile.lock": {"Gemfile.lock"},
"Gopkg.lock": {"TOML"},
"Guardfile": {"Ruby"},
"HOSTS": {"INI", "Hosts File"},
"HOSTS": {"Hosts File", "INI"},
"INSTALL": {"Text"},
"INSTALL.mysql": {"Text"},
"JUSTFILE": {"Just"},
@ -277,7 +277,7 @@ var LanguagesByFilename = map[string][]string{
"gradlew": {"Shell"},
"gvimrc": {"Vim Script"},
"haproxy.cfg": {"HAProxy"},
"hosts": {"INI", "Hosts File"},
"hosts": {"Hosts File", "INI"},
"httpd.conf": {"ApacheConf"},
"initial_sids": {"SELinux Policy"},
"inputrc": {"Readline Config"},

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
@ -91,7 +92,10 @@ func buildFilenameLanguageMap(languages map[string]*languageInfo) map[string][]s
func executeFilenamesTemplate(out io.Writer, languagesByFilename map[string][]string, tmplPath, tmplName, commit string) error {
fmap := template.FuncMap{
"formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` },
"formatStringSlice": func(slice []string) string {
sort.Strings(slice)
return `"` + strings.Join(slice, `","`) + `"`
},
}
return executeTemplate(out, tmplName, tmplPath, commit, fmap, languagesByFilename)
}