diff --git a/Makefile b/Makefile index a3e337978..2f44a5f51 100644 --- a/Makefile +++ b/Makefile @@ -116,6 +116,7 @@ gometalinter: require-gometalinter --enable=gochecknoinits \ --enable=gofmt \ --enable=goimports \ + --enable=gosimple \ --enable=gotype \ --enable=gotypex \ --enable=ineffassign \ diff --git a/boltdb/attrstore.go b/boltdb/attrstore.go index c6fa9bb76..09514360a 100644 --- a/boltdb/attrstore.go +++ b/boltdb/attrstore.go @@ -100,10 +100,8 @@ func (s *attrStore) Open() error { // Initialize database. if err := s.db.Update(func(tx *bolt.Tx) error { - if _, err := tx.CreateBucketIfNotExists([]byte("attrs")); err != nil { - return err - } - return nil + _, err := tx.CreateBucketIfNotExists([]byte("attrs")) + return err }); err != nil { return errors.Wrap(err, "initializing") } @@ -132,10 +130,7 @@ func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) { // Find attributes from storage. if err = s.db.View(func(tx *bolt.Tx) error { m, err = txAttrs(tx, id) - if err != nil { - return err - } - return nil + return err }); err != nil { return nil, errors.Wrap(err, "finding attributes") } diff --git a/cmd/check.go b/cmd/check.go index f9adf0980..d7bd33afd 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -40,10 +40,7 @@ Performs a consistency check on data files. return fmt.Errorf("path required") } checker.Paths = args - if err := checker.Run(context.Background()); err != nil { - return err - } - return nil + return checker.Run(context.Background()) }, } return checkCmd diff --git a/cmd/config.go b/cmd/config.go index 0288c34f0..a877d12ef 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -37,10 +37,7 @@ func newConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command RunE: func(cmd *cobra.Command, args []string) error { conf.Config = Server.Config - if err := conf.Run(context.Background()); err != nil { - return err - } - return nil + return conf.Run(context.Background()) }, } diff --git a/cmd/export.go b/cmd/export.go index 0a087e82a..217e9f09c 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -42,10 +42,7 @@ The format of the CSV file is: The file does not contain any headers. `, RunE: func(cmd *cobra.Command, args []string) error { - if err := Exporter.Run(context.Background()); err != nil { - return err - } - return nil + return Exporter.Run(context.Background()) }, } flags := exportCmd.Flags() diff --git a/cmd/generate_config.go b/cmd/generate_config.go index 7ff4b0833..6421a1f4f 100644 --- a/cmd/generate_config.go +++ b/cmd/generate_config.go @@ -34,10 +34,7 @@ func newGenerateConfigCommand(_ io.Reader, _, _ io.Writer) *cobra.Command { Long: `generate-config prints the default configuration to stdout `, RunE: func(cmd *cobra.Command, args []string) error { - if err := generateConf.Run(context.Background()); err != nil { - return err - } - return nil + return generateConf.Run(context.Background()) }, } diff --git a/cmd/import.go b/cmd/import.go index c726b805e..22e9b0117 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -43,10 +43,7 @@ omitted. If it is present then its format should be YYYY-MM-DDTHH:MM. `, RunE: func(cmd *cobra.Command, args []string) error { Importer.Paths = args - if err := Importer.Run(context.Background()); err != nil { - return err - } - return nil + return Importer.Run(context.Background()) }, } diff --git a/cmd/inspect.go b/cmd/inspect.go index f0f948807..4f5ff9301 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -43,10 +43,7 @@ Inspects a data file and provides stats. return fmt.Errorf("only one path allowed") } inspector.Path = args[0] - if err := inspector.Run(context.Background()); err != nil { - return err - } - return nil + return inspector.Run(context.Background()) }, } return inspectCmd diff --git a/ctl/import.go b/ctl/import.go index a16913f02..d3472acf1 100644 --- a/ctl/import.go +++ b/ctl/import.go @@ -232,11 +232,7 @@ func (cmd *ImportCommand) bufferBits(ctx context.Context, path string) error { } // If there are still bits in the buffer then flush them. - if err := cmd.importBits(ctx, a); err != nil { - return err - } - - return nil + return cmd.importBits(ctx, a) } // importBits sends batches of bits to the server. @@ -337,11 +333,7 @@ func (cmd *ImportCommand) bufferBitsK(ctx context.Context, path string) error { } // If there are still bitKs in the buffer then flush them. - if err := cmd.importBitsK(ctx, a); err != nil { - return err - } - - return nil + return cmd.importBitsK(ctx, a) } // importBitsK sends batches of bitKs to the server. @@ -426,11 +418,7 @@ func (cmd *ImportCommand) bufferValues(ctx context.Context, path string) error { } // If there are still values in the buffer then flush them. - if err := cmd.importValues(ctx, a); err != nil { - return err - } - - return nil + return cmd.importValues(ctx, a) } // importValues sends batches of FieldValues to the server. diff --git a/field.go b/field.go index af18d8666..b34d15c32 100644 --- a/field.go +++ b/field.go @@ -821,7 +821,7 @@ func groupCompare(a, b string, offset int) (lt, eq bool) { } func (f *Field) allTimeViewsSortedByQuantum() (me []*view) { - me = make([]*view, len(f.viewMap), len(f.viewMap)) + me = make([]*view, len(f.viewMap)) prefix := viewStandard + "_" offset := len(viewStandard) + 1 i := 0 diff --git a/fragment.go b/fragment.go index 36fab5fa3..2f57cccce 100644 --- a/fragment.go +++ b/fragment.go @@ -1713,8 +1713,7 @@ func (f *fragment) rows() []uint64 { i, _ := f.storage.Containers.Iterator(0) rows := make([]uint64, 0) - var lastRow uint64 - lastRow = math.MaxUint64 + var lastRow uint64 = math.MaxUint64 // Loop over the existing containers. for i.Next() { diff --git a/holder_internal_test.go b/holder_internal_test.go index 75a3508fd..566bc71f4 100644 --- a/holder_internal_test.go +++ b/holder_internal_test.go @@ -40,11 +40,7 @@ func (h *tHolder) Reopen() error { h.Holder = NewHolder() h.Holder.Path = path h.Holder.Logger = logger - if err := h.Holder.Open(); err != nil { - return err - } - - return nil + return h.Holder.Open() } func newHolder() *tHolder { diff --git a/pql/ast.go b/pql/ast.go index 88af892ad..cd483e030 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -441,9 +441,9 @@ func formatValue(v interface{}) string { case string: return fmt.Sprintf("%q", v) case []interface{}: - return fmt.Sprintf("%s", joinInterfaceSlice(v)) + return joinInterfaceSlice(v) case []uint64: - return fmt.Sprintf("%s", joinUint64Slice(v)) + return joinUint64Slice(v) case time.Time: return fmt.Sprintf("\"%s\"", v.Format(timeFormat)) case *Condition: diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 3a56e30f3..5bbcac86b 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -572,15 +572,11 @@ func TestIntersectBitmapRunBitmap(t *testing.T) { }, } for i, test := range tests { - for i, v := range test.bitmap { - a.bitmap[i] = v - } + copy(a.bitmap, test.bitmap) b.runs = test.runs b.n = 4097 // ;) exp := make([]uint64, bitmapN) - for i, v := range test.exp { - exp[i] = v - } + copy(exp, test.exp) a.containerType = containerBitmap b.containerType = containerRun ret := intersectBitmapRun(a, b) @@ -638,9 +634,7 @@ func TestIntersectBitmapRunArray(t *testing.T) { }, } for i, test := range tests { - for i, v := range test.bitmap { - a.bitmap[i] = v - } + copy(a.bitmap, test.bitmap) b.runs = test.runs a.containerType = containerBitmap b.containerType = containerRun @@ -962,9 +956,7 @@ func TestBitmapSetRange(t *testing.T) { } for i, test := range tests { - for i, v := range test.bitmap { - c.bitmap[i] = v - } + copy(c.bitmap, test.bitmap) c.n = c.countRange(0, 65535) c.bitmapSetRange(test.start, test.last+1) if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) { @@ -994,9 +986,7 @@ func TestArrayToBitmap(t *testing.T) { for i, test := range tests { exp := make([]uint64, bitmapN) - for i, v := range test.exp { - exp[i] = v - } + copy(exp, test.exp) a.array = test.array a.n = len(test.array) @@ -1084,7 +1074,7 @@ func TestRunToBitmap(t *testing.T) { } func getFullBitmap() []uint64 { - x := make([]uint64, 1024, 1024) + x := make([]uint64, 1024) for i := range x { x[i] = uint64(0xFFFFFFFFFFFFFFFF) } @@ -1264,9 +1254,7 @@ func TestBitmapZeroRange(t *testing.T) { } for i, test := range tests { - for i, v := range test.bitmap { - c.bitmap[i] = v - } + copy(c.bitmap, test.bitmap) c.n = c.countRange(0, 65535) c.bitmapZeroRange(test.start, test.last+1) if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) { @@ -1299,9 +1287,7 @@ func TestUnionBitmapRun(t *testing.T) { }, } for i, test := range tests { - for i, v := range test.bitmap { - a.bitmap[i] = v - } + copy(a.bitmap, test.bitmap) a.n = a.bitmapCountRange(0, 65535) b.runs = test.runs b.n = b.runCountRange(0, 65535) @@ -1346,9 +1332,7 @@ func TestBitmapCountRuns(t *testing.T) { } for i, test := range tests { - for j, v := range test.bitmap { - c.bitmap[j] = v - } + copy(c.bitmap, test.bitmap) ret := c.bitmapCountRuns() if ret != test.exp { @@ -1504,12 +1488,8 @@ func TestDifferenceRunArray(t *testing.T) { } } func MakeBitmap(start []uint64) []uint64 { - b := make([]uint64, bitmapN) - for i, v := range start { - b[i] = v - - } + copy(b, start) return b } func MakeLastBitSet() []uint64 { @@ -1571,9 +1551,7 @@ func TestDifferenceRunBitmap(t *testing.T) { for i, test := range tests { a.runs = test.runs a.n = a.runCountRange(0, 65536) - for i, v := range test.bitmap { - b.bitmap[i] = v - } + copy(b.bitmap, test.bitmap) b.n = b.bitmapCountRange(0, 65536) ret := differenceRunBitmap(a, b) if !reflect.DeepEqual(ret.runs, test.exp) { @@ -1652,9 +1630,7 @@ func TestDifferenceBitmapRun(t *testing.T) { }, } for i, test := range tests { - for i, v := range test.bitmap { - a.bitmap[i] = v - } + copy(a.bitmap, test.bitmap) a.n = a.bitmapCountRange(0, 65536) b.runs = test.runs b.n = b.runCountRange(0, 65536) @@ -2078,9 +2054,7 @@ func TestBitmapXorRange(t *testing.T) { } for i, test := range tests { - for i, v := range test.bitmap { - c.bitmap[i] = v - } + copy(c.bitmap, test.bitmap) c.n = c.countRange(0, 65535) c.bitmapXorRange(test.start, test.last+1) if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) { @@ -2595,9 +2569,7 @@ func TestIntersectArrayBitmap(t *testing.T) { for i, test := range tests { a.array = test.array a.containerType = containerArray - for i, bmval := range test.bitmap { - b.bitmap[i] = bmval - } + copy(b.bitmap, test.bitmap) b.containerType = containerBitmap ret := intersectArrayBitmap(a, b).array if len(ret) == 0 && len(test.exp) == 0 { diff --git a/test/holder.go b/test/holder.go index ff87ae02c..1d9790e2f 100644 --- a/test/holder.go +++ b/test/holder.go @@ -65,11 +65,7 @@ func (h *Holder) Reopen() error { h.Holder.Path = path h.Holder.Logger = logger h.Holder.NewAttrStore = boltdb.NewAttrStore - if err := h.Holder.Open(); err != nil { - return err - } - - return nil + return h.Holder.Open() } // MustCreateIndexIfNotExists returns a given index. Panic on error. diff --git a/test/pilosa.go b/test/pilosa.go index 507dd0af3..91f8d9a05 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -120,10 +120,7 @@ func (m *Command) Reopen() error { m.Command.Config = config // Run new program. - if err := m.Start(); err != nil { - return err - } - return nil + return m.Start() } // URL returns the base URL string for accessing the running program. diff --git a/translate.go b/translate.go index 6b3c1856b..580c08221 100644 --- a/translate.go +++ b/translate.go @@ -923,10 +923,8 @@ func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset in // Open initializes the reader. func (r *translateFileReader) Open() (err error) { - if r.file, err = os.Open(r.store.Path); err != nil { - return err - } - return nil + r.file, err = os.Open(r.store.Path) + return err } // Close closes the underlying file reader. diff --git a/translate_test.go b/translate_test.go index 693cca759..127c27348 100644 --- a/translate_test.go +++ b/translate_test.go @@ -568,10 +568,7 @@ func (s *TranslateFile) Reopen() error { s.lock.Unlock() s.Path = prev.Path s.PrimaryTranslateStore = prev.PrimaryTranslateStore - if err := s.Open(); err != nil { - return err - } - return nil + return s.Open() } // retryFor executes fn every 100ms until d time passes or until fn return nil.