From 7950b5d3b9b99146c08dfb991f767e923f248213 Mon Sep 17 00:00:00 2001 From: Michael Woolnough Date: Mon, 28 Oct 2024 10:46:14 +0000 Subject: [PATCH] Delint'd. --- cmd/decode.go | 21 +++++++++++++++------ main_test.go | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmd/decode.go b/cmd/decode.go index 70a1172d..68ab1561 100644 --- a/cmd/decode.go +++ b/cmd/decode.go @@ -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", @@ -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) @@ -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 + col = byUserGroupColumn + } else if strings.HasSuffix(file, ".stats") { + col = statsColumn + } else { _, err = io.Copy(os.Stdout, r) return err @@ -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 { diff --git a/main_test.go b/main_test.go index 02a12001..17e465a5 100644 --- a/main_test.go +++ b/main_test.go @@ -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")