Skip to content

Commit

Permalink
cleanup and update sniff match ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Nov 10, 2015
1 parent 2cc6b9a commit 946fa14
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions hound.go
Expand Up @@ -51,29 +51,27 @@ func (h *Hound) Sort() {
}

func (h *Hound) Sniff(fileName string, hunk *diff.Hunk) error {
r1, _ := regexp.Compile(`(?m)^\+\s*(.+)$`)
matches := r1.FindAllSubmatch(hunk.Body, -1)

r2, _ := regexp.Compile(`^\w+\/`)
fileName = r2.ReplaceAllString(fileName, "")
r1, _ := regexp.Compile(`^\w+\/`)
fileName = r1.ReplaceAllString(fileName, "")
if _, ok := h.MatchPatterns(h.Skips, []byte(fileName)); ok {
return nil
}

startLineNum := hunk.NewStartLine
r2, _ := regexp.Compile(`(?m)^\+\s*(.+)$`)
matches := r2.FindAllSubmatch(hunk.Body, -1)

for _, match := range matches {
line := match[1]

if pattern, ok := h.MatchPatterns(h.Warns, line); ok {
message := color.YellowString(fmt.Sprintf("Warning: pattern `%s` match found for `%s` starting at line %d in %s\n",
pattern, line, startLineNum, fileName))
pattern, line, hunk.NewStartLine, fileName))
fmt.Print(message)
}

if pattern, ok := h.MatchPatterns(h.Fails, line); ok {
err := color.RedString(fmt.Sprintf("Failure: pattern `%s` match found for `%s` starting at line %d in %s\n",
pattern, line, startLineNum, fileName))
pattern, line, hunk.NewStartLine, fileName))
return errors.New(err)
}
}
Expand Down

0 comments on commit 946fa14

Please sign in to comment.