Skip to content

Commit feeeebf

Browse files
committed
Upgrade golangci-lint, more linters
Introduces new linters, upgrade golangci-lint to version (v1.63.4)
1 parent 99dcc6b commit feeeebf

File tree

147 files changed

+3855
-2152
lines changed

Some content is hidden

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

147 files changed

+3855
-2152
lines changed

.golangci.yml

+30-17
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

api.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,38 @@ type API struct {
2929
// It uses the default Codecs and Interceptors unless you customize them
3030
// using WithMediaEngine and WithInterceptorRegistry respectively.
3131
func NewAPI(options ...func(*API)) *API {
32-
a := &API{
32+
api := &API{
3333
interceptor: &interceptor.NoOp{},
3434
settingEngine: &SettingEngine{},
3535
}
3636

3737
for _, o := range options {
38-
o(a)
38+
o(api)
3939
}
4040

41-
if a.settingEngine.LoggerFactory == nil {
42-
a.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
41+
if api.settingEngine.LoggerFactory == nil {
42+
api.settingEngine.LoggerFactory = logging.NewDefaultLoggerFactory()
4343
}
4444

45-
logger := a.settingEngine.LoggerFactory.NewLogger("api")
45+
logger := api.settingEngine.LoggerFactory.NewLogger("api")
4646

47-
if a.mediaEngine == nil {
48-
a.mediaEngine = &MediaEngine{}
49-
err := a.mediaEngine.RegisterDefaultCodecs()
47+
if api.mediaEngine == nil {
48+
api.mediaEngine = &MediaEngine{}
49+
err := api.mediaEngine.RegisterDefaultCodecs()
5050
if err != nil {
5151
logger.Errorf("Failed to register default codecs %s", err)
5252
}
5353
}
5454

55-
if a.interceptorRegistry == nil {
56-
a.interceptorRegistry = &interceptor.Registry{}
57-
err := RegisterDefaultInterceptors(a.mediaEngine, a.interceptorRegistry)
55+
if api.interceptorRegistry == nil {
56+
api.interceptorRegistry = &interceptor.Registry{}
57+
err := RegisterDefaultInterceptors(api.mediaEngine, api.interceptorRegistry)
5858
if err != nil {
5959
logger.Errorf("Failed to register default interceptors %s", err)
6060
}
6161
}
6262

63-
return a
63+
return api
6464
}
6565

6666
// WithMediaEngine allows providing a MediaEngine to the API.

atomicbool.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ func (b *atomicBool) swap(value bool) bool {
2727
if value {
2828
i = 1
2929
}
30+
3031
return atomic.SwapInt32(&(b.val), i) != 0
3132
}

bundlepolicy.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type BundlePolicy int
1515

1616
const (
17-
// BundlePolicyUnknown is the enum's zero-value
17+
// BundlePolicyUnknown is the enum's zero-value.
1818
BundlePolicyUnknown BundlePolicy = iota
1919

2020
// BundlePolicyBalanced indicates to gather ICE candidates for each
@@ -67,18 +67,19 @@ func (t BundlePolicy) String() string {
6767
}
6868
}
6969

70-
// UnmarshalJSON parses the JSON-encoded data and stores the result
70+
// UnmarshalJSON parses the JSON-encoded data and stores the result.
7171
func (t *BundlePolicy) UnmarshalJSON(b []byte) error {
7272
var val string
7373
if err := json.Unmarshal(b, &val); err != nil {
7474
return err
7575
}
7676

7777
*t = newBundlePolicy(val)
78+
7879
return nil
7980
}
8081

81-
// MarshalJSON returns the JSON encoding
82+
// MarshalJSON returns the JSON encoding.
8283
func (t BundlePolicy) MarshalJSON() ([]byte, error) {
8384
return json.Marshal(t.String())
8485
}

certificate.go

+25-13
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,36 @@ func NewCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*Certificate,
6262
return nil, &rtcerr.UnknownError{Err: err}
6363
}
6464

65-
return &Certificate{privateKey: key, x509Cert: cert, statsID: fmt.Sprintf("certificate-%d", time.Now().UnixNano())}, nil
65+
return &Certificate{
66+
privateKey: key,
67+
x509Cert: cert,
68+
statsID: fmt.Sprintf("certificate-%d", time.Now().UnixNano()),
69+
}, nil
6670
}
6771

6872
// Equals determines if two certificates are identical by comparing both the
6973
// secretKeys and x509Certificates.
70-
func (c Certificate) Equals(o Certificate) bool {
74+
func (c Certificate) Equals(cert Certificate) bool {
7175
switch cSK := c.privateKey.(type) {
7276
case *rsa.PrivateKey:
73-
if oSK, ok := o.privateKey.(*rsa.PrivateKey); ok {
77+
if oSK, ok := cert.privateKey.(*rsa.PrivateKey); ok {
7478
if cSK.N.Cmp(oSK.N) != 0 {
7579
return false
7680
}
77-
return c.x509Cert.Equal(o.x509Cert)
81+
82+
return c.x509Cert.Equal(cert.x509Cert)
7883
}
84+
7985
return false
8086
case *ecdsa.PrivateKey:
81-
if oSK, ok := o.privateKey.(*ecdsa.PrivateKey); ok {
87+
if oSK, ok := cert.privateKey.(*ecdsa.PrivateKey); ok {
8288
if cSK.X.Cmp(oSK.X) != 0 || cSK.Y.Cmp(oSK.Y) != 0 {
8389
return false
8490
}
85-
return c.x509Cert.Equal(o.x509Cert)
91+
92+
return c.x509Cert.Equal(cert.x509Cert)
8693
}
94+
8795
return false
8896
default:
8997
return false
@@ -95,6 +103,7 @@ func (c Certificate) Expires() time.Time {
95103
if c.x509Cert == nil {
96104
return time.Time{}
97105
}
106+
98107
return c.x509Cert.NotAfter
99108
}
100109

@@ -150,7 +159,7 @@ func GenerateCertificate(secretKey crypto.PrivateKey) (*Certificate, error) {
150159

151160
// CertificateFromX509 creates a new WebRTC Certificate from a given PrivateKey and Certificate
152161
//
153-
// This can be used if you want to share a certificate across multiple PeerConnections
162+
// This can be used if you want to share a certificate across multiple PeerConnections.
154163
func CertificateFromX509(privateKey crypto.PrivateKey, certificate *x509.Certificate) Certificate {
155164
return Certificate{privateKey, certificate, fmt.Sprintf("certificate-%d", time.Now().UnixNano())}
156165
}
@@ -176,11 +185,12 @@ func (c Certificate) collectStats(report *statsReportCollector) error {
176185
}
177186

178187
report.Collect(stats.ID, stats)
188+
179189
return nil
180190
}
181191

182192
// CertificateFromPEM creates a fresh certificate based on a string containing
183-
// pem blocks fort the private key and x509 certificate
193+
// pem blocks fort the private key and x509 certificate.
184194
func CertificateFromPEM(pems string) (*Certificate, error) {
185195
// decode & parse the certificate
186196
block, more := pem.Decode([]byte(pems))
@@ -206,18 +216,19 @@ func CertificateFromPEM(pems string) (*Certificate, error) {
206216
return nil, fmt.Errorf("unable to parse private key: %w", err)
207217
}
208218
x := CertificateFromX509(privateKey, cert)
219+
209220
return &x, nil
210221
}
211222

212223
// PEM returns the certificate encoded as two pem block: once for the X509
213-
// certificate and the other for the private key
224+
// certificate and the other for the private key.
214225
func (c Certificate) PEM() (string, error) {
215226
// First write the X509 certificate
216-
var o strings.Builder
227+
var builder strings.Builder
217228
xcertBytes := make(
218229
[]byte, base64.StdEncoding.EncodedLen(len(c.x509Cert.Raw)))
219230
base64.StdEncoding.Encode(xcertBytes, c.x509Cert.Raw)
220-
err := pem.Encode(&o, &pem.Block{Type: "CERTIFICATE", Bytes: xcertBytes})
231+
err := pem.Encode(&builder, &pem.Block{Type: "CERTIFICATE", Bytes: xcertBytes})
221232
if err != nil {
222233
return "", fmt.Errorf("failed to pem encode the X certificate: %w", err)
223234
}
@@ -226,9 +237,10 @@ func (c Certificate) PEM() (string, error) {
226237
if err != nil {
227238
return "", fmt.Errorf("failed to marshal private key: %w", err)
228239
}
229-
err = pem.Encode(&o, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
240+
err = pem.Encode(&builder, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
230241
if err != nil {
231242
return "", fmt.Errorf("failed to encode private key: %w", err)
232243
}
233-
return o.String(), nil
244+
245+
return builder.String(), nil
234246
}

configuration_common.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ func (c Configuration) getICEServers() []ICEServer {
2323
iceServers[iceServersIndex].URLs[urlsIndex] = rawURL
2424
}
2525
}
26+
2627
return iceServers
2728
}

configuration_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestConfiguration_getICEServers(t *testing.T) {
4343
}
4444

4545
func TestConfigurationJSON(t *testing.T) {
46-
j := `{
46+
config := `{
4747
"iceServers": [{"urls": ["turn:turn.example.org"],
4848
"username": "jch",
4949
"credential": "topsecret"
@@ -67,7 +67,7 @@ func TestConfigurationJSON(t *testing.T) {
6767
}
6868

6969
var conf2 Configuration
70-
assert.NoError(t, json.Unmarshal([]byte(j), &conf2))
70+
assert.NoError(t, json.Unmarshal([]byte(config), &conf2))
7171
assert.Equal(t, conf, conf2)
7272

7373
j2, err := json.Marshal(conf2)

constants.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import "github.com/pion/dtls/v3"
77

88
const (
99
// default as the standard ethernet MTU
10-
// can be overwritten with SettingEngine.SetReceiveMTU()
10+
// can be overwritten with SettingEngine.SetReceiveMTU().
1111
receiveMTU = 1500
1212

1313
// simulcastProbeCount is the amount of RTP Packets
1414
// that handleUndeclaredSSRC will read and try to dispatch from
15-
// mid and rid values
15+
// mid and rid values.
1616
simulcastProbeCount = 10
1717

1818
// simulcastMaxProbeRoutines is how many active routines can be used to probe
19-
// If the total amount of incoming SSRCes exceeds this new requests will be ignored
19+
// If the total amount of incoming SSRCes exceeds this new requests will be ignored.
2020
simulcastMaxProbeRoutines = 25
2121

2222
mediaSectionApplication = "application"
@@ -33,14 +33,21 @@ const (
3333

3434
generatedCertificateOrigin = "WebRTC"
3535

36-
// AttributeRtxPayloadType is the interceptor attribute added when Read() returns an RTX packet containing the RTX stream payload type
36+
// AttributeRtxPayloadType is the interceptor attribute added when Read()
37+
// returns an RTX packet containing the RTX stream payload type.
3738
AttributeRtxPayloadType = "rtx_payload_type"
38-
// AttributeRtxSsrc is the interceptor attribute added when Read() returns an RTX packet containing the RTX stream SSRC
39+
// AttributeRtxSsrc is the interceptor attribute added when Read()
40+
// returns an RTX packet containing the RTX stream SSRC.
3941
AttributeRtxSsrc = "rtx_ssrc"
40-
// AttributeRtxSequenceNumber is the interceptor attribute added when Read() returns an RTX packet containing the RTX stream sequence number
42+
// AttributeRtxSequenceNumber is the interceptor attribute added when
43+
// Read() returns an RTX packet containing the RTX stream sequence number.
4144
AttributeRtxSequenceNumber = "rtx_sequence_number"
4245
)
4346

4447
func defaultSrtpProtectionProfiles() []dtls.SRTPProtectionProfile {
45-
return []dtls.SRTPProtectionProfile{dtls.SRTP_AEAD_AES_256_GCM, dtls.SRTP_AEAD_AES_128_GCM, dtls.SRTP_AES128_CM_HMAC_SHA1_80}
48+
return []dtls.SRTPProtectionProfile{
49+
dtls.SRTP_AEAD_AES_256_GCM,
50+
dtls.SRTP_AEAD_AES_128_GCM,
51+
dtls.SRTP_AES128_CM_HMAC_SHA1_80,
52+
}
4653
}

0 commit comments

Comments
 (0)