Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to glangci lint #1774

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to use golangci-lint-action instead of shell actions, so that PRs are properly annotated with lint failures.

golangci-lint run -c ./jetstream/.golangci.yaml --timeout 5m0s ./jetstream/...

test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -71,4 +68,4 @@ jobs:
if: matrix.go == '1.23'
uses: coverallsapp/github-action@v2
with:
file: acc.out
file: acc.out
80 changes: 66 additions & 14 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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:"
2 changes: 0 additions & 2 deletions enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions encoders/protobuf/protobuf_enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions jetstream/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 3 additions & 3 deletions test/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions test/enc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions test/gob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions test/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions test/netchan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions test/protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading