Skip to content

Commit a34014a

Browse files
committed
Pending changes
1 parent cdab85e commit a34014a

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

cli/enry/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
log.Fatal(err)
2525
}
2626

27-
enry.LoadGitattributes()
27+
enry.LoadGitAttributes()
2828

2929
errors := false
3030
out := make(map[string][]string, 0)

common.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Strategy func(filename string, content []byte, candidates []string) (langua
1818

1919
// DefaultStrategies is the strategies' sequence GetLanguage uses to detect languages.
2020
var DefaultStrategies = []Strategy{
21-
GetLanguagesByGitattributes,
21+
GetLanguagesByGitAttributes,
2222
GetLanguagesByModeline,
2323
GetLanguagesByFilename,
2424
GetLanguagesByShebang,
@@ -96,10 +96,10 @@ func GetLanguageByClassifier(content []byte, candidates []string) (language stri
9696
return getLanguageByStrategy(GetLanguagesByClassifier, "", content, candidates)
9797
}
9898

99-
// GetLanguageByGitattributes returns the language assigned to a file for a given regular expresion in .gitattributes.
100-
// This strategy needs to be initialized calling LoadGitattributes
101-
func GetLanguageByGitattributes(filename string) (language string, safe bool) {
102-
return getLanguageByStrategy(GetLanguagesByGitattributes, filename, nil, nil)
99+
// GetLanguageByGitAttributes returns the language assigned to a file for a given regular expresion in .gitattributes.
100+
// This strategy needs to be initialized calling LoadGitAttributes
101+
func GetLanguageByGitAttributes(filename string) (language string, safe bool) {
102+
return getLanguageByStrategy(GetLanguagesByGitAttributes, filename, nil, nil)
103103
}
104104

105105
func getLanguageByStrategy(strategy Strategy, filename string, content []byte, candidates []string) (string, bool) {
@@ -450,15 +450,14 @@ func GetLanguageByAlias(alias string) (lang string, ok bool) {
450450
return
451451
}
452452

453-
// GetLanguagesByGitattributes returns a length 1 slice with the language assigned in .gitattributes if the regular expresion
454-
// matchs with the filename. It is comply with the signature to be a Strategy type.
455-
func GetLanguagesByGitattributes(filename string, content []byte, candidates []string) []string {
456-
languages := []string{}
457-
for regExp, language := range languageGitattributes {
453+
// GetLanguagesByGitAttributes returns either a string slice with the lenguage if the filename match with a regExp in .gitattributes
454+
//or return nil in case of none regexp matchs the filename . It complies with the signature to be a Strategy type.
455+
func GetLanguagesByGitAttributes(filename string, content []byte, candidates []string) []string {
456+
for regExp, language := range languageGitAttributes {
458457
if regExp.MatchString(filename) {
459-
return append(languages, language)
458+
return []string{language}
460459
}
461460
}
462461

463-
return languages
462+
return nil
464463
}

utils.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ var (
3030
"XML": true, "JSON": true, "TOML": true, "YAML": true, "INI": true, "SQL": true,
3131
}
3232

33-
vendorGitattributes = map[string]bool{}
34-
documentationGitattributes = map[string]bool{}
35-
languageGitattributes = map[*regexp.Regexp]string{}
33+
vendorGitAttributes = map[string]bool{}
34+
documentationGitAttributes = map[string]bool{}
35+
languageGitAttributes = map[*regexp.Regexp]string{}
3636
)
3737

3838
type OverrideError struct {
@@ -64,7 +64,7 @@ func IsDotFile(path string) bool {
6464

6565
// IsVendor returns whether or not path is a vendor path.
6666
func IsVendor(path string) bool {
67-
if val, ok := vendorGitattributes[path]; ok {
67+
if val, ok := vendorGitAttributes[path]; ok {
6868
return val
6969
}
7070

@@ -73,7 +73,7 @@ func IsVendor(path string) bool {
7373

7474
// IsDocumentation returns whether or not path is a documentation path.
7575
func IsDocumentation(path string) bool {
76-
if val, ok := documentationGitattributes[path]; ok {
76+
if val, ok := documentationGitAttributes[path]; ok {
7777
return val
7878
}
7979

@@ -97,14 +97,14 @@ func IsBinary(data []byte) bool {
9797
}
9898

9999
// LoadGitattributes reads and parses the file .gitattributes which overrides the standard strategies
100-
func LoadGitattributes() {
101-
rawAttributes, err := loadRawGitattributes(".gitattributes")
100+
func LoadGitAttributes() {
101+
rawAttributes, err := loadRawGitAttributes(".gitattributes")
102102
if err == nil && len(rawAttributes) > 0 {
103103
parseAttributes(rawAttributes)
104104
}
105105
}
106106

107-
func loadRawGitattributes(name string) (map[string][]string, error) {
107+
func loadRawGitAttributes(name string) (map[string][]string, error) {
108108
gitattributes := map[string][]string{}
109109
data, err := ioutil.ReadFile(name)
110110
if err != nil {
@@ -171,31 +171,31 @@ func parseAttribute(key string, attribute string) error {
171171

172172
func processVendorAttr(key string, attribute string) error {
173173
var err error
174-
if _, ok := vendorGitattributes[key]; ok {
174+
if _, ok := vendorGitAttributes[key]; ok {
175175
err = &OverrideError{attribute: "vendor", path: key}
176176
}
177177

178178
switch {
179179
case attribute == "linguist-vendored":
180-
vendorGitattributes[key] = true
180+
vendorGitAttributes[key] = true
181181
case attribute == "linguist-vendored=false":
182-
vendorGitattributes[key] = false
182+
vendorGitAttributes[key] = false
183183
}
184184

185185
return err
186186
}
187187

188188
func processDocumentationAttr(key string, attribute string) error {
189189
var err error
190-
if _, ok := documentationGitattributes[key]; ok {
190+
if _, ok := documentationGitAttributes[key]; ok {
191191
err = &OverrideError{attribute: "documentation", path: key}
192192
}
193193

194194
switch {
195195
case attribute == "linguist-documentation":
196-
documentationGitattributes[key] = true
196+
documentationGitAttributes[key] = true
197197
case attribute == "linguist-documentation=false":
198-
documentationGitattributes[key] = false
198+
documentationGitAttributes[key] = false
199199
}
200200

201201
return err
@@ -210,9 +210,9 @@ func processLanguageAttr(regExpString string, attribute string) error {
210210
}
211211
lang, _ := GetLanguageByAlias(tokens[1])
212212
if lang != OtherLanguage {
213-
languageGitattributes[regExp] = lang
213+
languageGitAttributes[regExp] = lang
214214
} else {
215-
languageGitattributes[regExp] = tokens[1]
215+
languageGitAttributes[regExp] = tokens[1]
216216
}
217217

218218
return nil

0 commit comments

Comments
 (0)