Skip to content

Commit

Permalink
Fix metalinter
Browse files Browse the repository at this point in the history
  • Loading branch information
iwat committed May 5, 2017
1 parent 67a550e commit 8d949bb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"strings"
)

// Engine is internal component for searching files and grep their contents
type Engine struct {
grepper *_Grepper
}

// NewEngine creates a new Engine.
func NewEngine() *Engine {
return &Engine{newGrepper()}
}

// Query will search files, grep contents, and return matching results.
func (e *Engine) Query(args ...string) []string {
var findArgs []string
var grepArgs []string
Expand Down
3 changes: 1 addition & 2 deletions internal/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ func newFinder(queries ...string) *_Finder {
if finder.shouldSkip(info.Name()) {
if info.IsDir() {
return filepath.SkipDir
} else {
return nil
}
return nil
}

if info.IsDir() {
Expand Down
8 changes: 6 additions & 2 deletions internal/grepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ func (g *_Grepper) grep(file string, keywords ...string) (bool, error) {
return false, err
}

defer func() { _ = f.Close() }()
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
for keyword, _ := range keywordMap {
for keyword := range keywordMap {
if bytes.Contains(scanner.Bytes(), []byte(keyword)) {
delete(keywordMap, keyword)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ type _StringMatcher struct {
func newMatcher(pattern string) (_Matcher, error) {
if len(pattern) > 2 && strings.HasPrefix(pattern, "/") && strings.HasSuffix(pattern, "/") {
return newRegexpMatcher(pattern)
} else {
return newStringMatcher(pattern), nil
}
return newStringMatcher(pattern), nil
}

func newStringMatcher(pattern string) _StringMatcher {
return _StringMatcher{strings.ToLower(pattern)}
}

func (m _StringMatcher) Matches(input string) bool {
lower_input := strings.ToLower(input)
lower := strings.ToLower(input)

return strings.Contains(lower_input, m.pattern)
return strings.Contains(lower, m.pattern)
}

type _RegexpMatcher struct {
Expand Down

0 comments on commit 8d949bb

Please sign in to comment.