Fix linter issues: gosimple

This commit is contained in:
Cody Soyland 2018-07-20 09:06:43 -05:00
parent c7e29b48f9
commit f01d850b17
18 changed files with 37 additions and 116 deletions

View file

@ -116,6 +116,7 @@ gometalinter: require-gometalinter
--enable=gochecknoinits \
--enable=gofmt \
--enable=goimports \
--enable=gosimple \
--enable=gotype \
--enable=gotypex \
--enable=ineffassign \

View file

@ -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")
}

View file

@ -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

View file

@ -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())
},
}

View file

@ -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()

View file

@ -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())
},
}

View file

@ -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())
},
}

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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() {

View file

@ -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 {

View file

@ -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:

View file

@ -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 {

View file

@ -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.

View file

@ -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.

View file

@ -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.

View file

@ -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.