From eb19b9bae43cf4c046fcebbdc208866c41e9f718 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 14:32:55 -0800 Subject: [PATCH 01/10] move js-spcecifig golangci config to jetstream/ --- jetstream/.golangci.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 jetstream/.golangci.yaml diff --git a/jetstream/.golangci.yaml b/jetstream/.golangci.yaml new file mode 100644 index 000000000..fb548e50e --- /dev/null +++ b/jetstream/.golangci.yaml @@ -0,0 +1,16 @@ +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" From 436d9f138da4512ea70add82f179a0834a7e8322 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 14:34:22 -0800 Subject: [PATCH 02/10] replace individual linters with golangci --- .github/workflows/ci.yaml | 9 +++----- .golangci.yaml | 44 +++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0ea16dee3..0beab5b2f 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/.goangci.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..7decf26de 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,16 +1,28 @@ -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" +run: + concurrency: 4 + issues-exit-code: 1 + tests: true + modules-download-mode: readonly + +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 + +run: + timeout: 5m + modules-download-mode: mod From bf8e66a1f1d8a8165377b6f278a044b1f6cfe623 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 14:51:42 -0800 Subject: [PATCH 03/10] nit --- .golangci.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 7decf26de..d51879e70 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,6 +3,7 @@ run: issues-exit-code: 1 tests: true modules-download-mode: readonly + timeout: 5m output: formats: @@ -22,7 +23,3 @@ linters: linters-settings: misspell: locale: US - -run: - timeout: 5m - modules-download-mode: mod From 72acb852cf7cde00f9afb92351d1f78a3090a2d2 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 15:07:34 -0800 Subject: [PATCH 04/10] nit --- .github/workflows/ci.yaml | 2 +- jetstream/.golangci.yaml | 41 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0beab5b2f..72d908e36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,7 +31,7 @@ jobs: shell: bash --noprofile --norc -x -eo pipefail {0} run: | GOFLAGS="-mod=mod -modfile=go_test.mod" golangci-lint run -c .golangci.yaml --timeout 5m0s ./... - golangci-lint run -c ./jetstream/.goangci.yaml --timeout 5m0s ./jetstream/... + golangci-lint run -c ./jetstream/.golangci.yaml --timeout 5m0s ./jetstream/... test: runs-on: ubuntu-latest diff --git a/jetstream/.golangci.yaml b/jetstream/.golangci.yaml index fb548e50e..d51879e70 100644 --- a/jetstream/.golangci.yaml +++ b/jetstream/.golangci.yaml @@ -1,16 +1,25 @@ -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" +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 From f3c50dbfe03c32a48909dc6264d5fadfd1b1a4bc Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 15:09:30 -0800 Subject: [PATCH 05/10] nit --- jetstream/.golangci.yaml | 41 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/jetstream/.golangci.yaml b/jetstream/.golangci.yaml index d51879e70..fb548e50e 100644 --- a/jetstream/.golangci.yaml +++ b/jetstream/.golangci.yaml @@ -1,25 +1,16 @@ -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 +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" From 1ce1b2920a15a0d6c8add761a4c4101358ed24ce Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 16:12:11 -0800 Subject: [PATCH 06/10] bring back default simplify: false --- .golangci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index d51879e70..60abfe429 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -23,3 +23,6 @@ linters: linters-settings: misspell: locale: US + gofmt: + # Simplify code: gofmt with `-s` option. + simplify: false From d91eec0b743b6807f254dacc6ac2a8649e22340b Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 16:28:10 -0800 Subject: [PATCH 07/10] default statichcheck config --- .golangci.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 60abfe429..a4b9aa971 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -26,3 +26,16 @@ linters-settings: 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" From a34fbb48610ef4ffc8a15b62a41ff72466cdb014 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 21:08:45 -0800 Subject: [PATCH 08/10] lint:ignore -> nolint --- test/context_test.go | 6 +++--- test/enc_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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..c6d0d28ed 100644 --- a/test/enc_test.go +++ b/test/enc_test.go @@ -1095,7 +1095,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") From 21d39eb73a26ef2eb0f0b68b47deb191774f0607 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 21:22:06 -0800 Subject: [PATCH 09/10] handle whole-file ignore for SA1019 --- .golangci.yaml | 27 +++++++++++++++++++++++++++ enc.go | 2 -- encoders/protobuf/protobuf_enc.go | 2 -- test/enc_test.go | 2 -- test/gob_test.go | 2 -- test/json_test.go | 2 -- test/netchan_test.go | 2 -- test/protobuf_test.go | 2 -- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index a4b9aa971..3f90e9d5b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -39,3 +39,30 @@ linters-settings: - "-ST1020" - "-ST1021" - "-ST1022" + +issues: + exclude-rules: + - 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/test/enc_test.go b/test/enc_test.go index c6d0d28ed..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 { 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 { From d6870212fa7bcba6e98c84ed290348a27bf16949 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Mon, 13 Jan 2025 21:28:35 -0800 Subject: [PATCH 10/10] explicitly enable only extra linters for js running golangci-lint -v shows: ``` level=info msg="[lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused]" ``` so let's enable only extra linters that are currntly configured for js, since config from repo root already has statickcheck and vet --- jetstream/.golangci.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jetstream/.golangci.yaml b/jetstream/.golangci.yaml index fb548e50e..8adcc61ef 100644 --- a/jetstream/.golangci.yaml +++ b/jetstream/.golangci.yaml @@ -1,3 +1,12 @@ +linters: + disable-all: true + enable: + - errcheck + - gosimple + - ineffassign + - unused + + issues: max-issues-per-linter: 0 max-same-issues: 0