Skip to content

Commit 1018320

Browse files
committed
Pending changes
1 parent bc3b27b commit 1018320

File tree

5 files changed

+12
-24
lines changed

5 files changed

+12
-24
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ Add a `.gitattributes` file to the directory and use the same matchers that you
134134

135135
#### Vendored code
136136

137-
138137
Use the `linguist-vendored` attribute to vendor or un-vendor paths.
139138

140139
```

cli/enry/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func main() {
7979
log.Println(err)
8080
return nil
8181
}
82+
8283
language := gitAttributes.GetLanguage(filepath.Base(path))
8384
if len(language) == 0 {
8485
language = enry.GetLanguage(filepath.Base(path), content)

common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,9 @@ func GetLanguagesBySpecificClassifier(content []byte, candidates []string, class
414414
return classifier.Classify(content, mapCandidates)
415415
}
416416

417-
// GetLanguagesByGitAttributes returns either a string slice with the language if the filename matches with a regExp in .gitattributes
418-
//or returns a empty slice in case no regexp matches the filename. It complies with the signature to be a Strategy type.
417+
// GetLanguagesByGitAttributes returns either a string slice with the language
418+
// if the filename matches with a regExp in .gitattributes or returns a empty slice
419+
// in case no regExp matches the filename. It complies with the signature to be a Strategy type.
419420
func GetLanguagesByGitAttributes(filename string, content []byte, candidates []string) []string {
420421
gitAttributes := NewGitAttributes()
421422
reader, err := os.Open(".gitattributes")

gitattributes.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"io/ioutil"
88
"regexp"
99
"strings"
10-
11-
"gopkg.in/src-d/enry.v1/data"
1210
)
1311

1412
type attrType int
@@ -28,6 +26,7 @@ func (i attrType) String() string {
2826
if i < 0 || i >= attrType(len(attrTypeIndex)-1) {
2927
return fmt.Sprintf("attrType(%d)", i)
3028
}
29+
3130
return attrTypeName[attrTypeIndex[i]:attrTypeIndex[i+1]]
3231
}
3332

@@ -42,7 +41,8 @@ type regExpAttribute struct {
4241
attributes map[*regexp.Regexp]string
4342
}
4443

45-
// GitAttributes is a struct that contains two maps, boolAttributes contains all the attributes that works like a boolean condition,
44+
// GitAttributes is a struct that contains two maps:
45+
// boolAttributes contains all the attributes that works like a boolean condition,
4646
// regExpAttributes contains all the attributes that match a regExp to choose if an attribute is applied or not
4747
type GitAttributes struct {
4848
boolAttributes map[attrType]boolAttribute
@@ -64,7 +64,7 @@ func (gitAttrs *GitAttributes) IsVendor(path string) bool {
6464
return val
6565
}
6666

67-
return data.VendorMatchers.Match(path)
67+
return IsVendor(path)
6868
}
6969

7070
// Returns whether or not path is a documentation path.
@@ -73,7 +73,7 @@ func (gitAttrs *GitAttributes) IsDocumentation(path string) bool {
7373
return val
7474
}
7575

76-
return data.DocumentationMatchers.Match(path)
76+
return IsDocumentation(path)
7777
}
7878

7979
// Returns whether or not path is a generated path.
@@ -113,8 +113,8 @@ func NewGitAttributes() *GitAttributes {
113113
return &gitAttrs
114114
}
115115

116-
// LoadGitattributes reads and parses the file .gitattributes which overrides the standard strategies
117-
// Returns slice of errors that have may ocurred in the load
116+
// LoadGitattributes reads and parses the file .gitattributes which overrides the standard strategies.
117+
// Returns slice of errors that have may ocurred in the load.
118118
func (gitAttrs *GitAttributes) LoadGitAttributes(path string, reader io.Reader) []error {
119119
rawAttributes, errArr := loadRawGitAttributes(reader)
120120
if len(rawAttributes) == 0 {
@@ -124,19 +124,6 @@ func (gitAttrs *GitAttributes) LoadGitAttributes(path string, reader io.Reader)
124124
return append(gitAttrs.parseAttributes(path, rawAttributes), errArr...)
125125
}
126126

127-
func (gitAttrs *GitAttributes) String() string {
128-
out := ""
129-
for key, val := range gitAttrs.boolAttributes {
130-
out += fmt.Sprintf("Type: %s Attributes: %v\n", key, val.attributes)
131-
}
132-
133-
for key, val := range gitAttrs.regExpAttributes {
134-
out += fmt.Sprintf("Type: %s Attributes: %v\n", key, val.attributes)
135-
}
136-
137-
return out
138-
}
139-
140127
func loadRawGitAttributes(reader io.Reader) (map[string][]string, []error) {
141128
rawAttributes := map[string][]string{}
142129
var errArr []error
@@ -216,6 +203,7 @@ func (gitAttrs *GitAttributes) processBoolAttr(kind attrType, key string, attrib
216203
if _, ok := gitAttrs.boolAttributes[kind].attributes[key]; ok {
217204
err = &overrideError{attribute: kind, path: key}
218205
}
206+
219207
switch {
220208
case attribute == gitAttrs.boolAttributes[kind].matchers[0]:
221209
gitAttrs.boolAttributes[kind].attributes[key] = true

gitattributes_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func (s *EnryTestSuite) TestLoadGitAttributes() {
2121
errArr := gitAttrs.LoadGitAttributes("test/", reader)
2222
if len(errArr) != 3 {
2323
fmt.Println(errArr)
24-
fmt.Println(gitAttrs.String())
2524
s.Fail("The error length it's not the expected")
2625
}
2726

0 commit comments

Comments
 (0)