Skip to content

Commit eae72a5

Browse files
committed
Use golangci instead of govet
1. Switch to use golangci instead of govet 2. Enable all linters in govet, except fieldalingment 3. Run `make fix` to fix all the linting problems 4. Fix awaitSchemaAgreement bug found by linters when error is not returned Patch by dkropachev; reviewed by joao-r-reis for CASSGO-77
1 parent 7279756 commit eae72a5

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

.golangci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "2"
2+
3+
issues:
4+
max-same-issues: 50
5+
6+
formatters:
7+
enable:
8+
- goimports
9+
10+
settings:
11+
goimports:
12+
local-prefixes:
13+
- github.com/gocql/gocql
14+
- github.com/apache/cassandra-gocql-driver
15+
golines:
16+
max-len: 120
17+
18+
linters:
19+
default: none
20+
enable:
21+
- nolintlint
22+
- govet
23+
settings:
24+
govet:
25+
enable-all: true
26+
disable:
27+
- shadow
28+
- fieldalignment
29+
30+
nolintlint:
31+
allow-no-explanation: [ golines ]
32+
require-explanation: true
33+
require-specific: true

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TEST_COMPRESSOR ?= no-compression
88
TEST_INTEGRATION_TAGS ?= integration
99

1010
CCM_VERSION ?= 39b8222b31a6c7afe8fe845d16981088a5a735ad
11+
GOLANGCI_VERSION = v2.1.6
1112
JVM_EXTRA_OPTS ?= -Dcassandra.test.fail_writes_ks=test -Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler
1213
ifeq (${CCM_CONFIG_DIR},)
1314
CCM_CONFIG_DIR = ~/.ccm
@@ -101,9 +102,15 @@ test-unit:
101102
@go clean -testcache
102103
go test -tags unit -timeout=5m -race ./...
103104

104-
check:
105-
@echo "Run go vet linter"
106-
go vet --tags "unit all cassandra integration" ./...
105+
check: .prepare-golangci
106+
@echo "Build"
107+
@go build -tags all .
108+
@echo "Check linting"
109+
@golangci-lint run
110+
111+
fix: .prepare-golangci
112+
@echo "Fix linting"
113+
golangci-lint run --fix
107114

108115
.prepare-java:
109116
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:
149156
@mkdir ${CCM_CONFIG_DIR} 2>/dev/null 1>&2 || true
150157
@echo ${CCM_VERSION} > ${CCM_CONFIG_DIR}/ccm-version
151158

159+
.prepare-golangci:
160+
@if ! golangci-lint --version 2>/dev/null | grep ${GOLANGCI_VERSION} >/dev/null; then \
161+
echo "Installing golangci-ling ${GOLANGCI_VERSION}"; \
162+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_VERSION}; \
163+
fi
164+

conn.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
19001900

19011901
var versions map[string]struct{}
19021902
var schemaVersion string
1903+
var rows []map[string]interface{}
19031904

19041905
endDeadline := time.Now().Add(c.session.cfg.MaxWaitSchemaAgreement)
19051906

@@ -1908,17 +1909,18 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
19081909

19091910
versions = make(map[string]struct{})
19101911

1911-
rows, err := iter.SliceMap()
1912+
rows, err = iter.SliceMap()
19121913
if err != nil {
19131914
goto cont
19141915
}
19151916

19161917
for _, row := range rows {
1917-
h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
1918+
var host *HostInfo
1919+
host, err = NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
19181920
if err != nil {
19191921
goto cont
19201922
}
1921-
host, err := c.session.hostInfoFromMap(row, h)
1923+
host, err = c.session.hostInfoFromMap(row, host)
19221924
if err != nil {
19231925
goto cont
19241926
}

lz4/lz4.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package lz4
2727
import (
2828
"encoding/binary"
2929
"fmt"
30+
3031
"github.com/pierrec/lz4/v4"
3132
)
3233

marshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ func unmarshalUDT(info TypeInfo, data []byte, value interface{}) error {
26032603
f, ok := fields[e.Name]
26042604
if !ok {
26052605
f = k.FieldByName(e.Name)
2606-
if f == emptyValue {
2606+
if f == emptyValue { //nolint:govet // there is no other way to compare with empty value
26072607
// skip fields which exist in the UDT but not in
26082608
// the struct passed in
26092609
continue

0 commit comments

Comments
 (0)