Skip to content

Commit

Permalink
fix: remove working directory from filename in report
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Sep 24, 2023
1 parent dcb2b9e commit 3fe6487
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pkg/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New(workingDirectory string, cfg *config.Config) (*Scan, error) {
}, nil
}

func scanForTodos(l *logrus.Entry, filename string, tags []string) ([]ScanResult, error) {
func scanForTodos(l *logrus.Entry, filename string, tags []string, workingDirectory string) ([]ScanResult, error) {
l.Debug("Scan starting")

f, err := os.Open(filename)
Expand Down Expand Up @@ -73,8 +73,13 @@ func scanForTodos(l *logrus.Entry, filename string, tags []string) ([]ScanResult
author := strings.TrimSpace(matches[3])
msg := strings.TrimSpace(matches[5])

// Remove working directory
cleanFilename := strings.TrimPrefix(filename, workingDirectory)
// Remove prefixed slash (may or may not be in working directory)
cleanFilename = strings.TrimPrefix(cleanFilename, "/")

res = append(res, ScanResult{
File: filename,
File: cleanFilename,
LineNumber: line,
Author: author,
Msg: msg,
Expand Down
2 changes: 1 addition & 1 deletion pkg/scanner/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *Scan) scanFilesForTodos(files []string) ([]ScanResult, error) {
l := logger.Log().WithField("file", file)

g.Go(func() error {
r, err := scanForTodos(l, file, s.config.Tags)
r, err := scanForTodos(l, file, s.config.Tags, s.workingDirectory)
if err != nil {
return err
}
Expand Down

0 comments on commit 3fe6487

Please sign in to comment.