diff --git a/pkg/scanner/scan.go b/pkg/scanner/scan.go index e2700b1..4129a17 100644 --- a/pkg/scanner/scan.go +++ b/pkg/scanner/scan.go @@ -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) @@ -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, diff --git a/pkg/scanner/types.go b/pkg/scanner/types.go index 85e2180..e96b761 100644 --- a/pkg/scanner/types.go +++ b/pkg/scanner/types.go @@ -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 }