Skip to content

Commit f2f92bb

Browse files
committed
Upgrade golangci-lint, more linters
Introduces new linters, upgrade golangci-lint to version (v1.63.4)
1 parent 289432d commit f2f92bb

File tree

108 files changed

+1702
-1128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1702
-1128
lines changed

.golangci.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,32 @@ linters-settings:
2525
- ^os.Exit$
2626
- ^panic$
2727
- ^print(ln)?$
28+
varnamelen:
29+
max-distance: 12
30+
min-name-length: 2
31+
ignore-type-assert-ok: true
32+
ignore-map-index-ok: true
33+
ignore-chan-recv-ok: true
34+
ignore-decls:
35+
- i int
36+
- n int
37+
- w io.Writer
38+
- r io.Reader
39+
- b []byte
2840

2941
linters:
3042
enable:
3143
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
3244
- bidichk # Checks for dangerous unicode character sequences
3345
- bodyclose # checks whether HTTP response body is closed successfully
46+
- containedctx # containedctx is a linter that detects struct contained context.Context field
3447
- contextcheck # check the function whether use a non-inherited context
48+
- cyclop # checks function and package cyclomatic complexity
3549
- decorder # check declaration order and count of types, constants, variables and functions
3650
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
3751
- dupl # Tool for code clone detection
3852
- durationcheck # check for two durations multiplied together
53+
- err113 # Golang linter to check the errors handling expressions
3954
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
4055
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
4156
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
@@ -46,66 +61,64 @@ linters:
4661
- forcetypeassert # finds forced type assertions
4762
- gci # Gci control golang package import order and make it always deterministic.
4863
- gochecknoglobals # Checks that no globals are present in Go code
49-
- gochecknoinits # Checks that no init functions are present in Go code
5064
- gocognit # Computes and checks the cognitive complexity of functions
5165
- goconst # Finds repeated strings that could be replaced by a constant
5266
- gocritic # The most opinionated Go source code linter
67+
- gocyclo # Computes and checks the cyclomatic complexity of functions
68+
- godot # Check if comments end in a period
5369
- godox # Tool for detection of FIXME, TODO and other comment keywords
54-
- err113 # Golang linter to check the errors handling expressions
5570
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
5671
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
5772
- goheader # Checks is file header matches to pattern
5873
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
5974
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
60-
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
6175
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
6276
- gosec # Inspects source code for security problems
6377
- gosimple # Linter for Go source code that specializes in simplifying a code
6478
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
6579
- grouper # An analyzer to analyze expression groups.
6680
- importas # Enforces consistent import aliases
6781
- ineffassign # Detects when assignments to existing variables are not used
82+
- lll # Reports long lines
83+
- maintidx # maintidx measures the maintainability index of each function.
84+
- makezero # Finds slice declarations with non-zero initial length
6885
- misspell # Finds commonly misspelled English words in comments
86+
- nakedret # Finds naked returns in functions greater than a specified function length
87+
- nestif # Reports deeply nested if statements
6988
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
7089
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
90+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
7191
- noctx # noctx finds sending http request without context.Context
7292
- predeclared # find code that shadows one of Go's predeclared identifiers
7393
- revive # golint replacement, finds style mistakes
7494
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
7595
- stylecheck # Stylecheck is a replacement for golint
7696
- tagliatelle # Checks the struct tags.
7797
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
78-
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
98+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
7999
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
80100
- unconvert # Remove unnecessary type conversions
81101
- unparam # Reports unused function parameters
82102
- unused # Checks Go code for unused constants, variables, functions and types
103+
- varnamelen # checks that the length of a variable's name matches its scope
83104
- wastedassign # wastedassign finds wasted assignment statements
84105
- whitespace # Tool for detection of leading and trailing whitespace
85106
disable:
86107
- depguard # Go linter that checks if package imports are in a list of acceptable packages
87-
- containedctx # containedctx is a linter that detects struct contained context.Context field
88-
- cyclop # checks function and package cyclomatic complexity
89108
- funlen # Tool for detection of long functions
90-
- gocyclo # Computes and checks the cyclomatic complexity of functions
91-
- godot # Check if comments end in a period
92-
- gomnd # An analyzer to detect magic numbers.
109+
- gochecknoinits # Checks that no init functions are present in Go code
110+
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
111+
- interfacebloat # A linter that checks length of interface.
93112
- ireturn # Accept Interfaces, Return Concrete Types
94-
- lll # Reports long lines
95-
- maintidx # maintidx measures the maintainability index of each function.
96-
- makezero # Finds slice declarations with non-zero initial length
97-
- nakedret # Finds naked returns in functions greater than a specified function length
98-
- nestif # Reports deeply nested if statements
99-
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
113+
- mnd # An analyzer to detect magic numbers
100114
- nolintlint # Reports ill-formed or insufficient nolint directives
101115
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
102116
- prealloc # Finds slice declarations that could potentially be preallocated
103117
- promlinter # Check Prometheus metrics naming via promlint
104118
- rowserrcheck # checks whether Err of rows is checked successfully
105119
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
106120
- testpackage # linter that makes you use a separate _test package
107-
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
108-
- varnamelen # checks that the length of a variable's name matches its scope
121+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
109122
- wrapcheck # Checks that errors returned from external packages are wrapped
110123
- wsl # Whitespace Linter - Forces you to use empty lines!
111124

@@ -123,3 +136,5 @@ issues:
123136
- path: cmd
124137
linters:
125138
- forbidigo
139+
max-issues-per-linter: 0
140+
max-same-issues: 0

attributes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919

2020
var errInvalidType = errors.New("found value of invalid type in attributes map")
2121

22-
// Attributes are a generic key/value store used by interceptors
22+
// Attributes are a generic key/value store used by interceptors.
2323
type Attributes map[interface{}]interface{}
2424

2525
// Get returns the attribute associated with key.
@@ -39,13 +39,15 @@ func (a Attributes) GetRTPHeader(raw []byte) (*rtp.Header, error) {
3939
if header, ok := val.(*rtp.Header); ok {
4040
return header, nil
4141
}
42+
4243
return nil, errInvalidType
4344
}
4445
header := &rtp.Header{}
4546
if _, err := header.Unmarshal(raw); err != nil {
4647
return nil, err
4748
}
4849
a[rtpHeaderKey] = header
50+
4951
return header, nil
5052
}
5153

@@ -57,12 +59,14 @@ func (a Attributes) GetRTCPPackets(raw []byte) ([]rtcp.Packet, error) {
5759
if packets, ok := val.([]rtcp.Packet); ok {
5860
return packets, nil
5961
}
62+
6063
return nil, errInvalidType
6164
}
6265
pkts, err := rtcp.Unmarshal(raw)
6366
if err != nil {
6467
return nil, err
6568
}
6669
a[rtcpPacketsKey] = pkts
70+
6771
return pkts, nil
6872
}

chain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func (i *Chain) UnbindLocalStream(ctx *StreamInfo) {
5050
}
5151
}
5252

53-
// BindRemoteStream lets you modify any incoming RTP packets. It is called once for per RemoteStream. The returned method
53+
// BindRemoteStream lets you modify any incoming RTP packets.
54+
// It is called once for per RemoteStream. The returned method
5455
// will be called once per rtp packet.
5556
func (i *Chain) BindRemoteStream(ctx *StreamInfo, reader RTPReader) RTPReader {
5657
for _, interceptor := range i.interceptors {

errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func flattenErrs(errs []error) error {
1818
if len(errs2) == 0 {
1919
return nil
2020
}
21+
2122
return multiError(errs2)
2223
}
2324

@@ -50,5 +51,6 @@ func (me multiError) Is(err error) bool {
5051
}
5152
}
5253
}
54+
5355
return false
5456
}

examples/nack/main.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ func receiveRoutine() {
5454

5555
// Create the writer just for a single SSRC stream
5656
// this is a callback that is fired everytime a RTP packet is ready to be sent
57-
streamReader := chain.BindRemoteStream(&interceptor.StreamInfo{
58-
SSRC: ssrc,
59-
RTCPFeedback: []interceptor.RTCPFeedback{{Type: "nack", Parameter: ""}},
60-
}, interceptor.RTPReaderFunc(func(b []byte, _ interceptor.Attributes) (int, interceptor.Attributes, error) { return len(b), nil, nil }))
57+
streamReader := chain.BindRemoteStream(
58+
&interceptor.StreamInfo{
59+
SSRC: ssrc,
60+
RTCPFeedback: []interceptor.RTCPFeedback{{Type: "nack", Parameter: ""}},
61+
},
62+
interceptor.RTPReaderFunc(
63+
func(b []byte, _ interceptor.Attributes) (int, interceptor.Attributes, error) {
64+
return len(b), nil, nil
65+
},
66+
),
67+
)
6168

6269
for rtcpBound, buffer := false, make([]byte, mtu); ; {
6370
i, addr, err := conn.ReadFrom(buffer)
@@ -88,6 +95,7 @@ func receiveRoutine() {
8895
}
8996
}
9097

98+
//nolint:cyclop
9199
func sendRoutine() {
92100
// Dial our UDP listener that we create in receiveRoutine
93101
serverAddr, err := net.ResolveUDPAddr("udp4", fmt.Sprintf("127.0.0.1:%d", listenPort))
@@ -116,9 +124,11 @@ func sendRoutine() {
116124

117125
// Set the interceptor wide RTCP Reader
118126
// this is a handle to send NACKs back into the interceptor.
119-
rtcpReader := chain.BindRTCPReader(interceptor.RTCPReaderFunc(func(in []byte, _ interceptor.Attributes) (int, interceptor.Attributes, error) {
120-
return len(in), nil, nil
121-
}))
127+
rtcpReader := chain.BindRTCPReader(
128+
interceptor.RTCPReaderFunc(func(in []byte, _ interceptor.Attributes) (int, interceptor.Attributes, error) {
129+
return len(in), nil, nil
130+
}),
131+
)
122132

123133
// Create the writer just for a single SSRC stream
124134
// this is a callback that is fired everytime a RTP packet is ready to be sent

interceptor.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/pion/rtp"
1313
)
1414

15-
// Factory provides an interface for constructing interceptors
15+
// Factory provides an interface for constructing interceptors.
1616
type Factory interface {
1717
NewInterceptor(id string) (Interceptor, error)
1818
}
@@ -35,7 +35,8 @@ type Interceptor interface {
3535
// UnbindLocalStream is called when the Stream is removed. It can be used to clean up any data related to that track.
3636
UnbindLocalStream(info *StreamInfo)
3737

38-
// BindRemoteStream lets you modify any incoming RTP packets. It is called once for per RemoteStream. The returned method
38+
// BindRemoteStream lets you modify any incoming RTP packets.
39+
// It is called once for per RemoteStream. The returned method
3940
// will be called once per rtp packet.
4041
BindRemoteStream(info *StreamInfo, reader RTPReader) RTPReader
4142

@@ -69,34 +70,34 @@ type RTCPReader interface {
6970
Read([]byte, Attributes) (int, Attributes, error)
7071
}
7172

72-
// RTPWriterFunc is an adapter for RTPWrite interface
73+
// RTPWriterFunc is an adapter for RTPWrite interface.
7374
type RTPWriterFunc func(header *rtp.Header, payload []byte, attributes Attributes) (int, error)
7475

75-
// RTPReaderFunc is an adapter for RTPReader interface
76+
// RTPReaderFunc is an adapter for RTPReader interface.
7677
type RTPReaderFunc func([]byte, Attributes) (int, Attributes, error)
7778

78-
// RTCPWriterFunc is an adapter for RTCPWriter interface
79+
// RTCPWriterFunc is an adapter for RTCPWriter interface.
7980
type RTCPWriterFunc func(pkts []rtcp.Packet, attributes Attributes) (int, error)
8081

81-
// RTCPReaderFunc is an adapter for RTCPReader interface
82+
// RTCPReaderFunc is an adapter for RTCPReader interface.
8283
type RTCPReaderFunc func([]byte, Attributes) (int, Attributes, error)
8384

84-
// Write a rtp packet
85+
// Write a rtp packet.
8586
func (f RTPWriterFunc) Write(header *rtp.Header, payload []byte, attributes Attributes) (int, error) {
8687
return f(header, payload, attributes)
8788
}
8889

89-
// Read a rtp packet
90+
// Read a rtp packet.
9091
func (f RTPReaderFunc) Read(b []byte, a Attributes) (int, Attributes, error) {
9192
return f(b, a)
9293
}
9394

94-
// Write a batch of rtcp packets
95+
// Write a batch of rtcp packets.
9596
func (f RTCPWriterFunc) Write(pkts []rtcp.Packet, attributes Attributes) (int, error) {
9697
return f(pkts, attributes)
9798
}
9899

99-
// Read a batch of rtcp packets
100+
// Read a batch of rtcp packets.
100101
func (f RTCPReaderFunc) Read(b []byte, a Attributes) (int, Attributes, error) {
101102
return f(b, a)
102103
}

internal/cc/acknowledgment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ func (a Acknowledgment) String() string {
2727
s += fmt.Sprintf("\tSIZE:\t%v\n", a.Size)
2828
s += fmt.Sprintf("\tDEPARTURE:\t%v\n", int64(float64(a.Departure.UnixNano())/1e+6))
2929
s += fmt.Sprintf("\tARRIVAL:\t%v\n", int64(float64(a.Arrival.UnixNano())/1e+6))
30+
3031
return s
3132
}

0 commit comments

Comments
 (0)