Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package main

import (
"bufio"
"os"
"path/filepath"
"strings"
)

var supportedExts = []string{
Expand Down Expand Up @@ -37,18 +37,19 @@ func process(fs fileSystem, filePaths []string) (poFile, error) {
if !isSupportedExt(filepath.Ext(filePath)) {
continue
}

content, err := fs.readFile(filePath)
if err != nil {
return poFile, err
f, e := os.Open(filePath)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert to err to keep in line with standard go practices.

Suggested change
f, e := os.Open(filePath)
f, err := os.Open(filePath)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep the tests working, this os.Open call needs to go through the fileSystem interface and then be mocked.

Or better yet, these days it's probably better to rely on fs.FS.

if e != nil {
panic(e)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to keep the panic()s in the main and use plain errors throughout the code base.

Suggested change
panic(e)
return poFile, err

}
defer f.Close()

scanner := bufio.NewScanner(strings.NewReader(string(content)))
r := bufio.NewReader(f)
line := 0
for scanner.Scan() {
s, e := Readln(r)
for e == nil {
line++

keys := extract(string(scanner.Text()))
linestr := s
keys := extract(linestr)
for _, key := range keys {
messageLoc := messageLocation{
File: filepath.Base(filePath),
Expand All @@ -74,12 +75,25 @@ func process(fs fileSystem, filePaths []string) (poFile, error) {
}

}
s, e = Readln(r)
}

}

return poFile, nil
}

func Readln(r *bufio.Reader) (string, error) {
var (
isPrefix bool = true
err error = nil
line, ln []byte
)
for isPrefix && err == nil {
line, isPrefix, err = r.ReadLine()
ln = append(ln, line...)
}
return string(ln), err
}
func isSupportedExt(ext string) bool {
for _, supportedExt := range supportedExts {
if ext == supportedExt {
Expand Down