Skip to content

Commit

Permalink
Delint'd.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkw31 committed Oct 28, 2024
1 parent e5cfddb commit 7950b5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cmd/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ import (
"github.com/wtsi-ssg/wrstat/v5/internal/encode"
)

const (
statsColumn = 0
byUserGroupColumn = 2
)

// chtsvCmd represents the chtsv command.
var decodeCmd = &cobra.Command{
Use: "decode",
Expand All @@ -52,7 +57,7 @@ Files with names ending in '.gz' will be decompressed before printing.
Other files are simply copied to stdout.
`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
for _, file := range args {
if err := decodeFile(file); err != nil {
die("%s", err)
Expand Down Expand Up @@ -87,9 +92,11 @@ func decodeFile(file string) error {

var col int

if strings.HasSuffix(file, ".byusergroup") {
col = 2
} else if !strings.HasSuffix(file, ".stats") {
if strings.HasSuffix(file, ".byusergroup") { //nolint:gocritic

Check failure on line 95 in cmd/decode.go

View workflow job for this annotation

GitHub Actions / lint

`if strings.HasSuffix(file, ".byusergroup")` has complex nested blocks (complexity: 2) (nestif)
col = byUserGroupColumn
} else if strings.HasSuffix(file, ".stats") {
col = statsColumn
} else {
_, err = io.Copy(os.Stdout, r)

return err
Expand All @@ -115,12 +122,14 @@ func decodeColumn(r io.Reader, col int) error {
}

if line == "\n" {
w.WriteString(line)
if _, err = w.WriteString(line); err != nil {
return err
}

continue
}

parts := strings.SplitN(line, "\t", col+2)
parts := strings.SplitN(line, "\t", col+2) //nolint:mnd

parts[col], err = encode.Base64Decode(parts[col])
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ func TestWalk(t *testing.T) {
}

func writeFileStringAndCompress(t *testing.T, path, contents string) {
t.Helper()

writeFileString(t, path, contents)

f, err := os.Create(path + ".gz")
Expand Down

0 comments on commit 7950b5d

Please sign in to comment.