Skip to content

Commit

Permalink
migrating golangci-lint to v1_30_0 and enabling some new linters
Browse files Browse the repository at this point in the history
  • Loading branch information
jgheewala committed Aug 11, 2020
1 parent f507183 commit e9a11ac
Show file tree
Hide file tree
Showing 34 changed files with 113 additions and 110 deletions.
12 changes: 9 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,23 @@ linters:
enable-all: true
disable:
- lll
- prealloc
- gochecknoinits
- gochecknoglobals
- errcheck
- unparam
- gosec
- interfacer
- dupl
# TODO: need to enable this two for better coding guidelines in terms of space between condition
- exhaustive
- whitespace
- wsl
- gci
- godot
- gomnd
- nestif
- nlreturn
# TODO: enable this linters later
- goerr113
- gochecknoinits
fast: true

# output configuration options
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go:
- "1.14.x"

before_install:
- "curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.21.0"
- "curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.30.0"

install:
- echo -e "Host heroku.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
Expand All @@ -18,8 +18,8 @@ script:
- export PATH=$(go env GOPATH)/bin:$PATH
- export GO111MODULE=on
- go mod download
- golangci-lint run
- go test -v -covermode atomic -race -timeout 70s -cpu 4 -parallel 8 -coverprofile ./coverage.out $(go list ./...)
- golangci-lint run -c .golangci.yml -v
- go test -v -covermode atomic -race -timeout 120s -cpu 4 -parallel 8 -coverprofile ./coverage.out $(go list ./...)
- "! go tool cover -func coverage.out | grep -v 100.0%"

after_script:
Expand Down
12 changes: 7 additions & 5 deletions boltcycle/boltcycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ func (s *Stats) AtomicClone() Stats {
}
}

var errUnableToFindRootBucket = errors.New("unable to find root bucket")
var errUnexpectedBucketBytes = errors.New("bucket bytes not in uint64 form")
var errUnexpectedNonBucket = errors.New("unexpected non bucket")
var errNoLastBucket = errors.New("unable to find a last bucket")
var errOrderingWrong = errors.New("ordering wrong")
var (
errUnableToFindRootBucket = errors.New("unable to find root bucket")
errUnexpectedBucketBytes = errors.New("bucket bytes not in uint64 form")
errUnexpectedNonBucket = errors.New("unexpected non bucket")
errNoLastBucket = errors.New("unable to find a last bucket")
errOrderingWrong = errors.New("ordering wrong")
)

// KvPair is a pair of key/value that you want to write during a write call
type KvPair struct {
Expand Down
3 changes: 1 addition & 2 deletions datapoint/dpsink/counter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dpsink

import (
"context"
"sync/atomic"
"time"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/event"
"github.com/signalfx/golib/v3/log"
Expand Down
3 changes: 1 addition & 2 deletions datapoint/dpsink/filter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dpsink

import (
"sync/atomic"

"context"
"sync/atomic"

"github.com/signalfx/golib/v3/datapoint"
)
Expand Down
3 changes: 1 addition & 2 deletions datapoint/dpsink/ratelimitlogger.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dpsink

import (
"context"
"sync/atomic"
"time"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/event"
"github.com/signalfx/golib/v3/log"
Expand Down
3 changes: 1 addition & 2 deletions datapoint/dptest/basicsink.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dptest

import (
"sync"

"context"
"sync"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/event"
Expand Down
21 changes: 8 additions & 13 deletions disco/disco.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@
package disco

import (
"bytes"
"crypto/rand"
"io"

"encoding/binary"
"encoding/json"
"fmt"
"sync/atomic"
"time"

"expvar"

"fmt"
"io"
"sort"
"strings"
"sync"

"bytes"
"encoding/binary"
"sort"

"github.com/signalfx/golib/v3/errors"
"sync/atomic"
"time"

"github.com/samuel/go-zookeeper/zk"
"github.com/signalfx/golib/v3/errors"
"github.com/signalfx/golib/v3/log"
"github.com/signalfx/golib/v3/logkey"
"github.com/signalfx/golib/v3/pointer"
Expand Down
9 changes: 3 additions & 6 deletions distconf/distconf.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package distconf

import (
"sync"

"time"

"math"

"expvar"
"math"
"runtime"
"sync"
"time"

"github.com/signalfx/golib/v3/log"
"github.com/signalfx/golib/v3/logkey"
Expand Down
1 change: 0 additions & 1 deletion distconf/ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func Ini(filename string) (Reader, error) {
filename: filename,
file: file,
}, nil

}

// IniLoader is a helper for loading from Ini files
Expand Down
2 changes: 0 additions & 2 deletions distconf/zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package distconf

import (
"fmt"

"sync"

"time"

"github.com/samuel/go-zookeeper/zk"
Expand Down
2 changes: 1 addition & 1 deletion env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func GetCommaSeparatedStringEnvVar(envVar string, def []string) []string {
}

// return a copy of the default
var ret = make([]string, len(def))
ret := make([]string, len(def))
_ = copy(ret, def)

return ret
Expand Down
8 changes: 5 additions & 3 deletions errors/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ type hasMessage interface {
Message() string
}

var _ causableError = &ErrorChain{}
var _ hasUnderline = &ErrorChain{}
var _ hasMessage = &ErrorChain{}
var (
_ causableError = &ErrorChain{}
_ hasUnderline = &ErrorChain{}
_ hasMessage = &ErrorChain{}
)

// Cause lets me simulate errgo
func (e *ErrorChain) Cause() error {
Expand Down
2 changes: 1 addition & 1 deletion event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func New(eventType string, category Category, dimensions map[string]string, time

// ToProtoEC - Converts a protbuf EventCategory to type event.Category
func ToProtoEC(ec sfxmodel.EventCategory) Category {
var response = USERDEFINED
response := USERDEFINED
// Check if the event.Category does not have a corresponding sfxmodel.EventCategory
if _, ok := sfxmodel.EventCategory_name[int32(ec)]; ok {
response = Category(ec)
Expand Down
6 changes: 2 additions & 4 deletions httpdebug/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ var DefaultConfig = &Config{
WriteTimeout: pointer.Duration(time.Duration(0)),
}

var (
// LogKeyHTTPClass is appended as a key to subloggers of the debug server
LogKeyHTTPClass = log.Key("http_class")
)
// LogKeyHTTPClass is appended as a key to subloggers of the debug server
var LogKeyHTTPClass = log.Key("http_class")

// New creates a new debug server
func New(conf *Config) *Server {
Expand Down
15 changes: 11 additions & 4 deletions metadata/aws/ec2metadata/ec2.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ec2metadata

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -83,10 +84,16 @@ func requestAWSInfo(url string) (metadata *EC2Metadata, err error) {
httpClient := &http.Client{Timeout: 200 * time.Millisecond}

// make the request
var res *http.Response
if res, err = httpClient.Get(url); err == nil {
err = json.NewDecoder(res.Body).Decode(metadata)
_ = res.Body.Close()
var (
res *http.Response
req *http.Request
)

if req, err = http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil); err == nil {
if res, err = httpClient.Do(req); err == nil {
err = json.NewDecoder(res.Body).Decode(metadata)
_ = res.Body.Close()
}
}

return metadata, err
Expand Down
27 changes: 17 additions & 10 deletions metadata/hostmetadata/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ const cpuTimeout = 10 * time.Second

// Map library functions to unexported package variables for testing purposes.
// It would be great if we could patch this somehow
var cpuInfo = cpu.InfoWithContext
var cpuCounts = cpu.CountsWithContext
var memVirtualMemory = mem.VirtualMemory
var hostInfo = host.Info
var (
cpuInfo = cpu.InfoWithContext
cpuCounts = cpu.CountsWithContext
memVirtualMemory = mem.VirtualMemory
hostInfo = host.Info
)

// CPU information about the host
type CPU struct {
Expand Down Expand Up @@ -122,9 +124,11 @@ func int8ArrayToByteArray(in []int8) []byte {
}

// GetOS returns a struct with information about the host os
func GetOS() (info *OS, err error) {
info = &OS{}
hInfo, err := hostInfo()
func GetOS() (*OS, error) {
var (
info = &OS{}
hInfo, err = hostInfo()
)

if err != nil {
return info, err
Expand Down Expand Up @@ -183,9 +187,12 @@ func GetMemory() (*Memory, error) {
}

func getStringFromFile(pattern string, path string) (string, error) {
var err error
var file []byte
var reg = regexp.MustCompile(pattern)
var (
err error
file []byte
reg = regexp.MustCompile(pattern)
)

if file, err = ioutil.ReadFile(path); err == nil {
if match := reg.FindSubmatch(file); len(match) > 1 {
return string(match[1]), nil
Expand Down
1 change: 0 additions & 1 deletion safeexec/safeexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package safeexec
import (
"bytes"
"os/exec"

"strings"

"github.com/signalfx/golib/v3/errors"
Expand Down
3 changes: 1 addition & 2 deletions sfxclient/datapointcreation.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package sfxclient

import (
"time"

"sync/atomic"
"time"

"github.com/signalfx/golib/v3/datapoint"
)
Expand Down
1 change: 1 addition & 0 deletions sfxclient/gometrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var GoMetricsSource Collector = &goMetrics{}

type goMetrics struct{}

// Datapoints will report current runtime stats of the process
func (g *goMetrics) Datapoints() []*datapoint.Datapoint {
mstat := runtime.MemStats{}
runtime.ReadMemStats(&mstat)
Expand Down
4 changes: 1 addition & 3 deletions sfxclient/httpsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,10 @@ func (h *HTTPSink) coreEventToProtobuf(event *event.Event) *sfxmodel.Event {
Timestamp: ts,
}
return ev

}

func mapToProperties(properties map[string]interface{}) []*sfxmodel.Property {
var response = make([]*sfxmodel.Property, 0, len(properties))
response := make([]*sfxmodel.Property, 0, len(properties))
for k, v := range properties {
kv := k
pv := rawToProtobuf(v)
Expand Down Expand Up @@ -469,7 +468,6 @@ func (h *HTTPSink) AddSpans(ctx context.Context, traces []*trace.Span) (err erro
}
return h.getReader(b)
}, h.contentTypeHeader, h.TraceEndpoint, spanResponseValidator)

}

func jsonMarshal(v []*trace.Span) ([]byte, error) {
Expand Down
Loading

0 comments on commit e9a11ac

Please sign in to comment.