diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ea16dee3..72d908e36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,11 +30,8 @@ jobs: - name: Run linters shell: bash --noprofile --norc -x -eo pipefail {0} run: | - $(exit $(go fmt -modfile=go_test.mod ./... | wc -l)) - go vet -modfile=go_test.mod ./... - GOFLAGS="-mod=mod -modfile=go_test.mod" staticcheck ./... - find . -type f -name "*.go" | xargs misspell -error -locale US - golangci-lint run --timeout 5m0s ./jetstream/... + GOFLAGS="-mod=mod -modfile=go_test.mod" golangci-lint run -c .golangci.yaml --timeout 5m0s ./... + golangci-lint run -c ./jetstream/.golangci.yaml --timeout 5m0s ./jetstream/... test: runs-on: ubuntu-latest @@ -71,4 +68,4 @@ jobs: if: matrix.go == '1.23' uses: coverallsapp/github-action@v2 with: - file: acc.out \ No newline at end of file + file: acc.out diff --git a/.golangci.yaml b/.golangci.yaml index fb548e50e..3f90e9d5b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,16 +1,68 @@ +run: + concurrency: 4 + issues-exit-code: 1 + tests: true + modules-download-mode: readonly + timeout: 5m + +output: + formats: + - format: colored-line-number + path: stdout + print-issued-lines: true + print-linter-name: true + +linters: + disable-all: true + enable: + - gofmt + - govet + - staticcheck + - misspell + +linters-settings: + misspell: + locale: US + gofmt: + # Simplify code: gofmt with `-s` option. + simplify: false + + staticcheck: + # SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks + # Example (to disable some checks): [ "all", "-SA1000", "-SA1001"] + # Default: ["*"] + checks: + - "all" + - "-SA1000" + - "-ST1003" + - "-ST1016" + - "-ST1020" + - "-ST1021" + - "-ST1022" + issues: - max-issues-per-linter: 0 - max-same-issues: 0 exclude-rules: - - linters: - - errcheck - text: "Unsubscribe" - - linters: - - errcheck - text: "Drain" - - linters: - - errcheck - text: "msg.Ack" - - linters: - - errcheck - text: "watcher.Stop" + - path: enc.go + linters: + - staticcheck + text: "SA1019:" + - path: enc_test.go + linters: + - staticcheck + text: "SA1019:" + - path: gob_test.go + linters: + - staticcheck + text: "SA1019:" + - path: json_test.go + linters: + - staticcheck + text: "SA1019:" + - path: netchan_test.go + linters: + - staticcheck + text: "SA1019:" + - path: protobuf_test.go + linters: + - staticcheck + text: "SA1019:" diff --git a/enc.go b/enc.go index 34a3fae7f..9db005a64 100644 --- a/enc.go +++ b/enc.go @@ -24,8 +24,6 @@ import ( "github.com/nats-io/nats.go/encoders/builtin" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - // Encoder interface is for all register encoders // // Deprecated: Encoded connections are no longer supported. diff --git a/encoders/protobuf/protobuf_enc.go b/encoders/protobuf/protobuf_enc.go index 805657767..baee599d1 100644 --- a/encoders/protobuf/protobuf_enc.go +++ b/encoders/protobuf/protobuf_enc.go @@ -20,8 +20,6 @@ import ( "google.golang.org/protobuf/proto" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - // Additional index for registered Encoders. const ( PROTOBUF_ENCODER = "protobuf" diff --git a/jetstream/.golangci.yaml b/jetstream/.golangci.yaml new file mode 100644 index 000000000..8adcc61ef --- /dev/null +++ b/jetstream/.golangci.yaml @@ -0,0 +1,25 @@ +linters: + disable-all: true + enable: + - errcheck + - gosimple + - ineffassign + - unused + + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + - linters: + - errcheck + text: "Unsubscribe" + - linters: + - errcheck + text: "Drain" + - linters: + - errcheck + text: "msg.Ack" + - linters: + - errcheck + text: "watcher.Stop" diff --git a/test/context_test.go b/test/context_test.go index f2df307a6..22395dafe 100644 --- a/test/context_test.go +++ b/test/context_test.go @@ -718,7 +718,7 @@ func TestFlushWithContext(t *testing.T) { ctx := context.Background() // No context should error. - //lint:ignore SA1012 testing that passing nil fails + //nolint:staticcheck // SA1012 testing that passing nil fails if err := nc.FlushWithContext(nil); err != nats.ErrInvalidContext { t.Fatalf("Expected '%v', got '%v'", nats.ErrInvalidContext, err) } @@ -786,7 +786,7 @@ func TestContextInvalid(t *testing.T) { nc := NewDefaultConnection(t) defer nc.Close() - //lint:ignore SA1012 testing that passing nil fails + //nolint:staticcheck // SA1012 testing that passing nil fails _, err := nc.RequestWithContext(nil, "foo", []byte("")) if err == nil { t.Fatal("Expected request to fail with error") @@ -800,7 +800,7 @@ func TestContextInvalid(t *testing.T) { t.Fatalf("Expected to be able to subscribe: %s", err) } - //lint:ignore SA1012 testing that passing nil fails + //nolint:staticcheck // SA1012 testing that passing nil fails _, err = sub.NextMsgWithContext(nil) if err == nil { t.Fatal("Expected request to fail with error") diff --git a/test/enc_test.go b/test/enc_test.go index c8109e7af..a1bb285fc 100644 --- a/test/enc_test.go +++ b/test/enc_test.go @@ -27,8 +27,6 @@ import ( "github.com/nats-io/nats.go/encoders/protobuf/testdata" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - func NewDefaultEConn(t *testing.T) *nats.EncodedConn { ec, err := nats.NewEncodedConn(NewConnection(t, TEST_PORT), nats.DEFAULT_ENCODER) if err != nil { @@ -1095,7 +1093,7 @@ func TestEncodedContextInvalid(t *testing.T) { } req := &request{Message: "Hello"} resp := &response{} - //lint:ignore SA1012 testing that passing nil fails + //nolint:staticcheck // SA1012 testing that passing nil fails err = c.RequestWithContext(nil, "slow", req, resp) if err == nil { t.Fatal("Expected request to fail with error") diff --git a/test/gob_test.go b/test/gob_test.go index f326f8c9f..c772e1074 100644 --- a/test/gob_test.go +++ b/test/gob_test.go @@ -20,8 +20,6 @@ import ( "github.com/nats-io/nats.go" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - func NewGobEncodedConn(tl TestLogger) *nats.EncodedConn { ec, err := nats.NewEncodedConn(NewConnection(tl, TEST_PORT), nats.GOB_ENCODER) if err != nil { diff --git a/test/json_test.go b/test/json_test.go index cebbf31ec..4ef6f42c5 100644 --- a/test/json_test.go +++ b/test/json_test.go @@ -22,8 +22,6 @@ import ( "github.com/nats-io/nats.go/encoders/builtin" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - func NewJsonEncodedConn(tl TestLogger) *nats.EncodedConn { ec, err := nats.NewEncodedConn(NewConnection(tl, TEST_PORT), nats.JSON_ENCODER) if err != nil { diff --git a/test/netchan_test.go b/test/netchan_test.go index f21d32921..eb457b36d 100644 --- a/test/netchan_test.go +++ b/test/netchan_test.go @@ -20,8 +20,6 @@ import ( "github.com/nats-io/nats.go" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - // NewEConn func NewEConn(t tLogger) *nats.EncodedConn { ec, err := nats.NewEncodedConn(NewDefaultConnection(t), nats.DEFAULT_ENCODER) diff --git a/test/protobuf_test.go b/test/protobuf_test.go index d4bee8c85..08fdf6771 100644 --- a/test/protobuf_test.go +++ b/test/protobuf_test.go @@ -25,8 +25,6 @@ import ( pb "github.com/nats-io/nats.go/encoders/protobuf/testdata" ) -//lint:file-ignore SA1019 Ignore deprecation warnings for EncodedConn - func NewProtoEncodedConn(tl TestLogger) *nats.EncodedConn { ec, err := nats.NewEncodedConn(NewConnection(tl, TEST_PORT), protobuf.PROTOBUF_ENCODER) if err != nil {