From 3c89ea6b33ce796ba379a2efa4800878a286fa6e Mon Sep 17 00:00:00 2001 From: Chun-Hung Tseng Date: Tue, 2 Apr 2024 18:02:22 +0200 Subject: [PATCH] Address linter issues --- Makefile | 2 +- cmd/analyze.go | 4 ++-- cmd/checksum.go | 2 +- cmd/decode.go | 7 +++---- cmd/encode.go | 2 +- cmd/extract.go | 6 +++--- pkg/data/data.go | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 1bf8bc6..245f76d 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ fmt: .PHONY: verify verify: - golangci-lint run ./... + golangci-lint run --config tools/.golangci.yaml ./... # Local development build build: diff --git a/cmd/analyze.go b/cmd/analyze.go index 061e6a1..fbc4207 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -36,7 +36,7 @@ type analyzeOptions struct { filename string } -var analyzeOpts *analyzeOptions = &analyzeOptions{} +var analyzeOpts = &analyzeOptions{} func init() { RootCmd.AddCommand(analyzeCmd) @@ -52,7 +52,7 @@ func analyzeValidateAndRun() error { objectCounts := map[string]uint{} for _, s := range summaries { if s.TypeMeta != nil { - objectCounts[fmt.Sprintf("%s/%s", s.TypeMeta.APIVersion, s.TypeMeta.Kind)] += 1 + objectCounts[fmt.Sprintf("%s/%s", s.TypeMeta.APIVersion, s.TypeMeta.Kind)]++ } } diff --git a/cmd/checksum.go b/cmd/checksum.go index 9d42511..803b1cf 100644 --- a/cmd/checksum.go +++ b/cmd/checksum.go @@ -36,7 +36,7 @@ type checksumOptions struct { revision int64 } -var checksumOpts *checksumOptions = &checksumOptions{} +var checksumOpts = &checksumOptions{} func init() { RootCmd.AddCommand(checksumCmd) diff --git a/cmd/decode.go b/cmd/decode.go index 3c67749..2f23442 100644 --- a/cmd/decode.go +++ b/cmd/decode.go @@ -73,7 +73,7 @@ type decodeOptions struct { batchProcess bool // special flag to handle incoming etcd-dump-logs output } -var options *decodeOptions = &decodeOptions{} +var options = &decodeOptions{} func init() { RootCmd.AddCommand(decodeCmd) @@ -124,7 +124,7 @@ func runInBatchMode(metaOnly bool, outMediaType string, out io.Writer) (err erro return nil } if err != nil { - return fmt.Errorf("error reading --batch-process input: %v\n", err) + return fmt.Errorf("error reading --batch-process input: %v", err) } input = stripNewline(input) @@ -210,7 +210,6 @@ func readInput(inputFilename string) ([]byte, error) { func stripNewline(d []byte) []byte { if len(d) > 0 && d[len(d)-1] == '\n' { return d[:len(d)-1] - } else { - return d } + return d } diff --git a/cmd/encode.go b/cmd/encode.go index 2236d9a..e3798e4 100644 --- a/cmd/encode.go +++ b/cmd/encode.go @@ -51,7 +51,7 @@ type encodeOptions struct { inputFilename string } -var encodeOpts *encodeOptions = &encodeOptions{} +var encodeOpts = &encodeOptions{} func init() { RootCmd.AddCommand(encodeCmd) diff --git a/cmd/extract.go b/cmd/extract.go index fc1bedc..4759434 100644 --- a/cmd/extract.go +++ b/cmd/extract.go @@ -90,7 +90,7 @@ type extractOptions struct { filter string } -var opts *extractOptions = &extractOptions{} +var opts = &extractOptions{} func init() { RootCmd.AddCommand(extractCmd) @@ -250,7 +250,7 @@ func printLeafItemValue(kv *mvccpb.KeyValue, outMediaType string, out io.Writer) // printKeySummaries prints all keys in the db file with the given key prefix. func printKeySummaries(filename string, keyPrefix string, revision int64, fields []string, out io.Writer) error { if len(fields) == 0 { - return fmt.Errorf("no fields provided, nothing to output.") + return fmt.Errorf("no fields provided, nothing to output") } var hasKey bool @@ -288,7 +288,7 @@ func printTemplateSummaries(filename string, keyPrefix string, revision int64, t } if len(templatestr) == 0 { - return fmt.Errorf("no template provided, nothing to output.") + return fmt.Errorf("no template provided, nothing to output") } filters := []data.Filter{} diff --git a/pkg/data/data.go b/pkg/data/data.go index cf50cf5..f25c149 100644 --- a/pkg/data/data.go +++ b/pkg/data/data.go @@ -272,7 +272,7 @@ func ListKeySummaries(filename string, filters []Filter, proj *KeySummaryProject ks.Version = kv.ModRevision ks.Stats.ValueSize = len(kv.Value) } - ks.Stats.VersionCount += 1 + ks.Stats.VersionCount++ ks.Stats.AllVersionsKeySize += len(kv.Key) ks.Stats.AllVersionsValueSize += len(kv.Value) }