diff --git a/.golangci.yml b/.golangci.yml index 39fb158..560b540 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,20 +4,33 @@ run: silent: true linters-settings: + errcheck: + check-blank: true + gocognit: + min-complexity: 50 + gocritic: + enabled-tags: + - diagnostic + - performance + - style lll: line-length: 180 linters: enable-all: true disable: - - gas - - interfacer - - maligned - - nakedret + - funlen + - gas + - gochecknoglobals + - interfacer + - maligned + - nakedret + - stylecheck + - wsl issues: exclude-use-default: false exclude: - - composite literal uses unkeyed fields - - Error return value of `.+\.Close` is not checked - - method Json should be JSON + - composite literal uses unkeyed fields + - Error return value of `.+\.Close` is not checked + - method Json should be JSON diff --git a/Makefile b/Makefile index 334847f..e270e3c 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,6 @@ ifndef GOBIN export GOBIN := $(GOPATH)/bin endif -define dl - @curl -sSq -L $(2) -o $(GOBIN)/$(1) && chmod u+x $(GOBIN)/$(1) -endef - define dl_tgz @curl -sSq -L $(2) | tar zxf - --strip 1 -C $(GOBIN) --wildcards '*/$(1)' endef @@ -40,4 +36,4 @@ get-deps: .PHONY: get-tools get-tools: @echo "==> Installing tools at $(GOBIN)..." - @$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v1.10.2/golangci-lint-1.10.2-linux-amd64.tar.gz) + @$(call dl_tgz,golangci-lint,https://github.com/golangci/golangci-lint/releases/download/v1.21.0/golangci-lint-1.21.0-linux-amd64.tar.gz) diff --git a/gocqlxtest/gocqlxtest.go b/gocqlxtest/gocqlxtest.go index 5725d62..552793e 100644 --- a/gocqlxtest/gocqlxtest.go +++ b/gocqlxtest/gocqlxtest.go @@ -7,7 +7,6 @@ package gocqlxtest import ( "flag" "fmt" - "log" "strings" "sync" "testing" @@ -24,16 +23,8 @@ var ( flagRetry = flag.Int("retries", 5, "number of times to retry queries") flagCompressTest = flag.String("compressor", "", "compressor to use") flagTimeout = flag.Duration("gocql.timeout", 5*time.Second, "sets the connection `timeout` for all operations") - - clusterHosts []string ) -func init() { - flag.Parse() - clusterHosts = strings.Split(*flagCluster, ",") - log.SetFlags(log.Lshortfile | log.LstdFlags) -} - var initOnce sync.Once // CreateSession creates a new gocql session from flags. @@ -43,6 +34,11 @@ func CreateSession(tb testing.TB) *gocql.Session { } func createCluster() *gocql.ClusterConfig { + if !flag.Parsed() { + flag.Parse() + } + clusterHosts := strings.Split(*flagCluster, ",") + cluster := gocql.NewCluster(clusterHosts...) cluster.ProtoVersion = *flagProto cluster.CQLVersion = *flagCQL diff --git a/migrate/checksum.go b/migrate/checksum.go index 8202a05..681045d 100644 --- a/migrate/checksum.go +++ b/migrate/checksum.go @@ -30,5 +30,5 @@ func fileChecksum(path string) (string, error) { return "", err } v := h.Sum(nil) - return encode(v[:]), nil + return encode(v), nil } diff --git a/qb/batch.go b/qb/batch.go index 09666ba..e6509ed 100644 --- a/qb/batch.go +++ b/qb/batch.go @@ -76,7 +76,7 @@ func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuild // AddStmtWithPrefix adds statement to the batch. Names are prefixed with // the prefix + ".". -func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder { +func (b *BatchBuilder) AddStmtWithPrefix(prefix, stmt string, names []string) *BatchBuilder { b.stmts = append(b.stmts, stmt) for _, name := range names { if prefix != "" { diff --git a/qb/select.go b/qb/select.go index b1cbf0b..14c71e6 100644 --- a/qb/select.go +++ b/qb/select.go @@ -230,7 +230,6 @@ func (b *SelectBuilder) Sum(column string) *SelectBuilder { return b } -func (b *SelectBuilder) fn(name, column string) *SelectBuilder { +func (b *SelectBuilder) fn(name, column string) { b.Columns(name + "(" + column + ")") - return b } diff --git a/queryx.go b/queryx.go index e100645..ade2908 100644 --- a/queryx.go +++ b/queryx.go @@ -33,7 +33,8 @@ func CompileNamedQuery(qs []byte) (stmt string, names []string, err error) { for i, b := range qs { // a ':' while we're in a name is an error - if b == ':' { + switch { + case b == ':': // if this is the second ':' in a '::' escape sequence, append a ':' if inName && i > 0 && qs[i-1] == ':' { rebound = append(rebound, ':') @@ -46,11 +47,11 @@ func CompileNamedQuery(qs []byte) (stmt string, names []string, err error) { inName = true name = []byte{} // if we're in a name, and this is an allowed character, continue - } else if inName && (allowedBindRune(b) || b == '_' || b == '.') && i != last { + case inName && (allowedBindRune(b) || b == '_' || b == '.') && i != last: // append the byte to the name if we are in a name and not on the last byte name = append(name, b) // if we're in a name and it's not an allowed character, the name is done - } else if inName { + case inName: inName = false // if this is the final byte of the string and it is part of the name, then // make sure to add it to the name @@ -67,7 +68,7 @@ func CompileNamedQuery(qs []byte) (stmt string, names []string, err error) { } else if !allowedBindRune(b) { rebound = append(rebound, b) } - } else { + default: // this is a normal byte and should just go onto the rebound query rebound = append(rebound, b) } @@ -137,7 +138,7 @@ func bindStructArgs(names []string, arg0 interface{}, arg1 map[string]interface{ err := m.TraversalsByNameFunc(v.Type(), names, func(i int, t []int) error { if len(t) != 0 { - val := reflectx.FieldByIndexesReadOnly(v, t) + val := reflectx.FieldByIndexesReadOnly(v, t) // nolint:scopelint arglist = append(arglist, val.Interface()) } else { val, ok := arg1[names[i]] diff --git a/table/table.go b/table/table.go index b93bf7f..9e6acdf 100644 --- a/table/table.go +++ b/table/table.go @@ -32,7 +32,7 @@ type Table struct { } // New creates new Table based on table schema read from Metadata. -func New(m Metadata) *Table { +func New(m Metadata) *Table { // nolint: gocritic t := &Table{ metadata: m, }