diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..f0ff7d329 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,33 @@ +version: "2" + +issues: + max-same-issues: 50 + +formatters: + enable: + - goimports + + settings: + goimports: + local-prefixes: + - github.com/gocql/gocql + - github.com/apache/cassandra-gocql-driver + golines: + max-len: 120 + +linters: + default: none + enable: + - nolintlint + - govet + settings: + govet: + enable-all: true + disable: + - shadow + - fieldalignment + + nolintlint: + allow-no-explanation: [ golines ] + require-explanation: true + require-specific: true diff --git a/Makefile b/Makefile index 4ef54d28c..56ed015db 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ TEST_COMPRESSOR ?= no-compression TEST_INTEGRATION_TAGS ?= integration CCM_VERSION ?= 39b8222b31a6c7afe8fe845d16981088a5a735ad +GOLANGCI_VERSION = v2.1.6 JVM_EXTRA_OPTS ?= -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler ifeq (${CCM_CONFIG_DIR},) CCM_CONFIG_DIR = ~/.ccm @@ -101,9 +102,15 @@ test-unit: @go clean -testcache go test -tags unit -timeout=5m -race ./... -check: - @echo "Run go vet linter" - go vet --tags "unit all cassandra integration" ./... +check: .prepare-golangci + @echo "Build" + @go build -tags all . + @echo "Check linting" + @golangci-lint run + +fix: .prepare-golangci + @echo "Fix linting" + golangci-lint run --fix .prepare-java: ifeq ($(shell if [ -f ~/.sdkman/bin/sdkman-init.sh ]; then echo "installed"; else echo "not-installed"; fi), not-installed) @@ -149,3 +156,9 @@ install-ccm: @mkdir ${CCM_CONFIG_DIR} 2>/dev/null 1>&2 || true @echo ${CCM_VERSION} > ${CCM_CONFIG_DIR}/ccm-version +.prepare-golangci: + @if ! golangci-lint --version 2>/dev/null | grep ${GOLANGCI_VERSION} >/dev/null; then \ + echo "Installing golangci-ling ${GOLANGCI_VERSION}"; \ + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_VERSION}; \ + fi + diff --git a/conn.go b/conn.go index 114f159d8..93f6cab1a 100644 --- a/conn.go +++ b/conn.go @@ -1900,6 +1900,7 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) { var versions map[string]struct{} var schemaVersion string + var rows []map[string]interface{} endDeadline := time.Now().Add(c.session.cfg.MaxWaitSchemaAgreement) @@ -1908,17 +1909,18 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) { versions = make(map[string]struct{}) - rows, err := iter.SliceMap() + rows, err = iter.SliceMap() if err != nil { goto cont } for _, row := range rows { - h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port) + var host *HostInfo + host, err = NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port) if err != nil { goto cont } - host, err := c.session.hostInfoFromMap(row, h) + host, err = c.session.hostInfoFromMap(row, host) if err != nil { goto cont } diff --git a/lz4/lz4.go b/lz4/lz4.go index c836a0934..f97cbd377 100644 --- a/lz4/lz4.go +++ b/lz4/lz4.go @@ -27,6 +27,7 @@ package lz4 import ( "encoding/binary" "fmt" + "github.com/pierrec/lz4/v4" ) diff --git a/marshal.go b/marshal.go index 368c7f12c..d0cf6730b 100644 --- a/marshal.go +++ b/marshal.go @@ -2603,7 +2603,7 @@ func unmarshalUDT(info TypeInfo, data []byte, value interface{}) error { f, ok := fields[e.Name] if !ok { f = k.FieldByName(e.Name) - if f == emptyValue { + if f == emptyValue { //nolint:govet // there is no other way to compare with empty value // skip fields which exist in the UDT but not in // the struct passed in continue