Skip to content

Commit

Permalink
feat(ci): golangci-lint config
Browse files Browse the repository at this point in the history
Signed-off-by: Cattī Crūdēlēs <[email protected]>
  • Loading branch information
wzy9607 committed Feb 9, 2024
1 parent 28756c2 commit 41f83ca
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 16 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI
on:
push:
branches:
- main
pull_request:

permissions:
contents: read
jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Run golangci-lint
uses: golangci/[email protected]
with:
version: latest
221 changes: 221 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
run:
timeout: 10m
show-stats: true

output:
sort-results: true

linters-settings:
cyclop:
max-complexity: 15
package-average: 10
skip-tests: true
dupl:
threshold: 120
errcheck:
exclude-functions:
- encoding/json.Marshal
- encoding/json.MarshalIndent
errchkjson:
check-error-free-encoding: true
report-no-exported: true
exhaustive:
check:
- switch
- map
default-signifies-exhaustive: true
gci:
sections:
- standard
- default
- prefix(github.com/rabbitmq/amqp091-go)
- prefix(github.com/wzy9607/amqp091otel)
custom-order: true
gocritic:
enabled-tags:
- diagnostic
- style
- performance
- experimental
- opinionated
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- hugeParam
- ifElseChain
- ruleguard
- sloppyReassign
- whyNoLint
settings:
captLocal:
paramsOnly: false
unnamedResult:
checkExported: true
gofmt:
simplify: false # covered by gofumpt
rewrite-rules:
- pattern: "interface{}"
replacement: "any"
- pattern: "a[b:len(a)]"
replacement: "a[b:]"
gomnd:
checks:
- argument
- case
- condition
- return
ignored-functions:
- strings.SplitN
govet:
check-shadowing: true
enable-all: true
disable:
- fieldalignment
grouper:
import-require-single-import: true
nakedret:
max-func-lines: 50
nolintlint:
allow-unused: false
require-explanation: true
require-specific: true
revive:
rules:
- name: argument-limit
arguments:
- 8
- name: atomic
- name: bool-literal-in-expr
- name: confusing-results
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: datarace
- name: defer
- name: error-naming
- name: error-return
arguments:
- "preserveScope"
- name: errorf
- name: increment-decrement
- name: indent-error-flow
- name: modifies-value-receiver
- name: optimize-operands-order
- name: redundant-import-alias
- name: string-of-int
- name: struct-tag
- name: superfluous-else
- name: time-equal
- name: time-naming
- name: var-naming
stylecheck:
checks:
- "all"
- "-ST1000"
usestdlibvars:
http-method: true
http-status-code: true
time-weekday: true
time-month: true
time-layout: true
crypto-hash: true
default-rpc-path: true
os-dev-null: true
sql-isolation-level: true
tls-signature-scheme: true
constant-kind: true
syslog-priority: true
varnamelen:
max-distance: 10

linters:
enable:
- asasalint
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gocheckcompilerdirectives
- gochecksumtype
- goconst
- gocritic
- gofmt
- gofumpt
- gomnd
- gomoddirectives
- gosec
- gosimple
- govet
- grouper
- inamedparam
- ineffassign
- interfacebloat
- lll
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- paralleltest
- perfsprint
- predeclared
- reassign
- revive
- spancheck
- staticcheck
- stylecheck
- tagalign
- tenv
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- varnamelen
- wastedassign
- whitespace


issues:
include:
- EXC0003
- EXC0004
- EXC0005
- EXC0006
exclude-rules:
- path: _test\.go
linters:
- containedctx
- dupl
- exhaustive
- exhaustruct
- forcetypeassert
- funlen
- gomnd
- nakedret
- varnamelen
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 2 additions & 2 deletions acknowledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type acknowledger struct {
ch *Channel
ctx context.Context
ctx context.Context //nolint:containedctx // consumer needs to retrieve the context via ContextFromDelivery.
span trace.Span
}

Expand All @@ -23,7 +23,7 @@ func (a *acknowledger) Ack(tag uint64, multiple bool) error {
return err
}

func (a *acknowledger) Nack(tag uint64, multiple bool, requeue bool) error {
func (a *acknowledger) Nack(tag uint64, multiple, requeue bool) error {
err := a.ch.Channel.Nack(tag, multiple, requeue)
if multiple {
a.endMultiple(tag, codes.Error, "nack", err)
Expand Down
9 changes: 6 additions & 3 deletions carrier.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package amqp091otel

import (
"github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/propagation"

"github.com/rabbitmq/amqp091-go"
)

var _ propagation.TextMapCarrier = (*publishingMessageCarrier)(nil)
var _ propagation.TextMapCarrier = (*deliveryMessageCarrier)(nil)
var (
_ propagation.TextMapCarrier = (*publishingMessageCarrier)(nil)
_ propagation.TextMapCarrier = (*deliveryMessageCarrier)(nil)
)

// publishingMessageCarrier injects and extracts traces from a amqp091.Publishing.
type publishingMessageCarrier struct {
Expand Down
11 changes: 10 additions & 1 deletion carrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package amqp091otel
import (
"testing"

"github.com/rabbitmq/amqp091-go"
"github.com/stretchr/testify/assert"

"github.com/rabbitmq/amqp091-go"
)

func Test_publishingMessageCarrier_Get(t *testing.T) {
Expand Down Expand Up @@ -39,7 +40,9 @@ func Test_publishingMessageCarrier_Get(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := publishingMessageCarrier{
msg: tt.fields.msg,
}
Expand Down Expand Up @@ -88,7 +91,9 @@ func Test_publishingMessageCarrier_Keys(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := publishingMessageCarrier{
msg: tt.fields.msg,
}
Expand Down Expand Up @@ -130,7 +135,9 @@ func Test_deliveryMessageCarrier_Get(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := deliveryMessageCarrier{
msg: tt.fields.msg,
}
Expand Down Expand Up @@ -179,7 +186,9 @@ func Test_deliveryMessageCarrier_Keys(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
c := deliveryMessageCarrier{
msg: tt.fields.msg,
}
Expand Down
15 changes: 8 additions & 7 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"strings"
"sync"

"github.com/rabbitmq/amqp091-go"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.23.0"
"go.opentelemetry.io/otel/trace"

"github.com/rabbitmq/amqp091-go"
)

const (
Expand Down Expand Up @@ -61,8 +62,8 @@ func (ch *Channel) commonAttrs() []attribute.KeyValue {
}
}

func (*Channel) nameWhenPublish(exchange, key string) string {
if len(exchange) == 0 {
func (*Channel) nameWhenPublish(exchange string) string {
if exchange == "" {
exchange = "(default)"
}
return exchange + " publish"
Expand Down Expand Up @@ -102,7 +103,8 @@ func (ch *Channel) startConsumerSpan(msg *amqp091.Delivery, queue string, operat
trace.WithSpanKind(trace.SpanKindConsumer),
}

ctx, span := ch.cfg.Tracer.Start(parentCtx, ch.nameWhenConsume(queue), opts...)
ctx, span := ch.cfg.Tracer.Start(parentCtx, //nolint:spancheck // span ends when msg is ack/nack/rejected
ch.nameWhenConsume(queue), opts...)
msg.Acknowledger = &acknowledger{
ch: ch,
ctx: ctx,
Expand All @@ -112,7 +114,7 @@ func (ch *Channel) startConsumerSpan(msg *amqp091.Delivery, queue string, operat
ch.m.Lock()
defer ch.m.Unlock()
ch.spanMap[msg.DeliveryTag] = span
}
} //nolint:spancheck // span ends when msg is ack/nack/rejected

func (ch *Channel) Consume(
queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args amqp091.Table,
Expand Down Expand Up @@ -161,14 +163,13 @@ func (ch *Channel) PublishWithDeferredConfirmWithContext(
trace.WithAttributes(attrs...),
trace.WithSpanKind(trace.SpanKindProducer),
}
ctx, span := ch.cfg.Tracer.Start(ctx, ch.nameWhenPublish(exchange, key), opts...)
ctx, span := ch.cfg.Tracer.Start(ctx, ch.nameWhenPublish(exchange), opts...)

// Inject current span context
carrier := newPublishingMessageCarrier(&msg)
ch.cfg.Propagators.Inject(ctx, carrier)

dc, err := ch.Channel.PublishWithDeferredConfirmWithContext(ctx, exchange, key, mandatory, immediate, msg)

if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
Expand Down
Loading

0 comments on commit 41f83ca

Please sign in to comment.