| 72 | } |
| 73 | |
| 74 | func analyzeFile(issues []Issue, file string) (map[string][]Finding, error) { |
| 75 | findings := make(map[string][]Finding) |
| 76 | |
| 77 | readFile, err := os.Open(file) |
| 78 | if err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | defer readFile.Close() |
| 82 | |
| 83 | scanner := bufio.NewScanner(readFile) |
| 84 | lineNumber := 0 |
| 85 | for scanner.Scan() { |
| 86 | lineNumber++ |
| 87 | line := scanner.Text() |
| 88 | |
| 89 | for _, issue := range issues { |
| 90 | matched, _ := regexp.MatchString(issue.Pattern, line) |
| 91 | if matched { |
| 92 | findings[issue.Identifier] = append(findings[issue.Identifier], Finding{ |
| 93 | IssueIdentifier: issue.Identifier, |
| 94 | File: file, |
| 95 | LineNumber: lineNumber, |
| 96 | LineContent: strings.TrimSpace(line), |
| 97 | }) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return findings, nil |
| 103 | } |