Skip to content

Commit ec84594

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

33 files changed

+517
-240
lines changed

.golangci.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
23
# SPDX-License-Identifier: MIT
34

@@ -25,17 +26,32 @@ linters-settings:
2526
- ^os.Exit$
2627
- ^panic$
2728
- ^print(ln)?$
29+
varnamelen:
30+
max-distance: 12
31+
min-name-length: 2
32+
ignore-type-assert-ok: true
33+
ignore-map-index-ok: true
34+
ignore-chan-recv-ok: true
35+
ignore-decls:
36+
- i int
37+
- n int
38+
- w io.Writer
39+
- r io.Reader
40+
- b []byte
2841

2942
linters:
3043
enable:
3144
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
3245
- bidichk # Checks for dangerous unicode character sequences
3346
- bodyclose # checks whether HTTP response body is closed successfully
47+
- containedctx # containedctx is a linter that detects struct contained context.Context field
3448
- contextcheck # check the function whether use a non-inherited context
49+
- cyclop # checks function and package cyclomatic complexity
3550
- decorder # check declaration order and count of types, constants, variables and functions
3651
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
3752
- dupl # Tool for code clone detection
3853
- durationcheck # check for two durations multiplied together
54+
- err113 # Golang linter to check the errors handling expressions
3955
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
4056
- 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.
4157
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
@@ -46,66 +62,64 @@ linters:
4662
- forcetypeassert # finds forced type assertions
4763
- gci # Gci control golang package import order and make it always deterministic.
4864
- gochecknoglobals # Checks that no globals are present in Go code
49-
- gochecknoinits # Checks that no init functions are present in Go code
5065
- gocognit # Computes and checks the cognitive complexity of functions
5166
- goconst # Finds repeated strings that could be replaced by a constant
5267
- gocritic # The most opinionated Go source code linter
68+
- gocyclo # Computes and checks the cyclomatic complexity of functions
69+
- godot # Check if comments end in a period
5370
- godox # Tool for detection of FIXME, TODO and other comment keywords
54-
- err113 # Golang linter to check the errors handling expressions
5571
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
5672
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
5773
- goheader # Checks is file header matches to pattern
5874
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
5975
- 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.
6176
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
6277
- gosec # Inspects source code for security problems
6378
- gosimple # Linter for Go source code that specializes in simplifying a code
6479
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
6580
- grouper # An analyzer to analyze expression groups.
6681
- importas # Enforces consistent import aliases
6782
- ineffassign # Detects when assignments to existing variables are not used
83+
- lll # Reports long lines
84+
- maintidx # maintidx measures the maintainability index of each function.
85+
- makezero # Finds slice declarations with non-zero initial length
6886
- misspell # Finds commonly misspelled English words in comments
87+
- nakedret # Finds naked returns in functions greater than a specified function length
88+
- nestif # Reports deeply nested if statements
6989
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
7090
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
91+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
7192
- noctx # noctx finds sending http request without context.Context
7293
- predeclared # find code that shadows one of Go's predeclared identifiers
7394
- revive # golint replacement, finds style mistakes
7495
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
7596
- stylecheck # Stylecheck is a replacement for golint
7697
- tagliatelle # Checks the struct tags.
7798
- 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
99+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
79100
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
80101
- unconvert # Remove unnecessary type conversions
81102
- unparam # Reports unused function parameters
82103
- unused # Checks Go code for unused constants, variables, functions and types
104+
- varnamelen # checks that the length of a variable's name matches its scope
83105
- wastedassign # wastedassign finds wasted assignment statements
84106
- whitespace # Tool for detection of leading and trailing whitespace
85107
disable:
86108
- 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
89109
- 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.
110+
- gochecknoinits # Checks that no init functions are present in Go code
111+
- 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.
112+
- interfacebloat # A linter that checks length of interface.
93113
- 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
114+
- mnd # An analyzer to detect magic numbers
100115
- nolintlint # Reports ill-formed or insufficient nolint directives
101116
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
102117
- prealloc # Finds slice declarations that could potentially be preallocated
103118
- promlinter # Check Prometheus metrics naming via promlint
104119
- rowserrcheck # checks whether Err of rows is checked successfully
105120
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
106121
- 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
122+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
109123
- wrapcheck # Checks that errors returned from external packages are wrapped
110124
- wsl # Whitespace Linter - Forces you to use empty lines!
111125

application_defined.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (a ApplicationDefined) Marshal() ([]byte, error) {
3838
packetSize := a.MarshalSize()
3939
header := Header{
4040
Type: TypeApplicationDefined,
41-
Length: uint16((packetSize / 4) - 1),
41+
Length: uint16((packetSize / 4) - 1), //nolint:gosec // G115
4242
Padding: paddingSize != 0,
4343
Count: a.SubType,
4444
}
@@ -110,13 +110,14 @@ func (a *ApplicationDefined) Unmarshal(rawPacket []byte) error {
110110
return nil
111111
}
112112

113-
// MarshalSize returns the size of the packet once marshaled
113+
// MarshalSize returns the size of the packet once marshaled.
114114
func (a *ApplicationDefined) MarshalSize() int {
115115
dataLength := len(a.Data)
116116
// Calculate the padding size to be added to make the packet length a multiple of 4 bytes.
117117
paddingSize := 4 - (dataLength % 4)
118118
if paddingSize == 4 {
119119
paddingSize = 0
120120
}
121+
121122
return 12 + dataLength + paddingSize
122123
}

application_defined_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ func TestTApplicationPacketUnmarshal(t *testing.T) {
144144
t.Fatalf("SSRC %q result: got packet SSRC %x instead of %x", test.Name, apk.SSRC, 0x4baae1ab)
145145
}
146146
if apk.SSRC != apk.DestinationSSRC()[0] {
147-
t.Fatalf("SSRC %q result: DestinationSSRC() %x doesn't match SSRC field %x", test.Name, apk.DestinationSSRC()[0], apk.SSRC)
147+
t.Fatalf(
148+
"SSRC %q result: DestinationSSRC() %x doesn't match SSRC field %x",
149+
test.Name, apk.DestinationSSRC()[0], apk.SSRC,
150+
)
148151
}
149152
}
150153
}

compound_packet.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
type CompoundPacket []Packet
2424

2525
// Validate returns an error if this is not an RFC-compliant CompoundPacket.
26+
//
27+
//nolint:cyclop
2628
func (c CompoundPacket) Validate() error {
2729
if len(c) == 0 {
2830
return errEmptyCompound
@@ -72,7 +74,7 @@ func (c CompoundPacket) Validate() error {
7274
return errMissingCNAME
7375
}
7476

75-
// CNAME returns the CNAME that *must* be present in every CompoundPacket
77+
// CNAME returns the CNAME that *must* be present in every CompoundPacket.
7678
func (c CompoundPacket) CNAME() (string, error) {
7779
var err error
7880

@@ -97,6 +99,7 @@ func (c CompoundPacket) CNAME() (string, error) {
9799
}
98100
}
99101
}
102+
100103
return "", errMissingCNAME
101104
}
102105

@@ -107,15 +110,17 @@ func (c CompoundPacket) Marshal() ([]byte, error) {
107110
}
108111

109112
p := []Packet(c)
113+
110114
return Marshal(p)
111115
}
112116

113-
// MarshalSize returns the size of the packet once marshaled
117+
// MarshalSize returns the size of the packet once marshaled.
114118
func (c CompoundPacket) MarshalSize() int {
115119
l := 0
116120
for _, p := range c {
117121
l += p.MarshalSize()
118122
}
123+
119124
return l
120125
}
121126

@@ -157,5 +162,6 @@ func (c CompoundPacket) String() string {
157162
}
158163
}
159164
out = strings.TrimSuffix(strings.ReplaceAll(out, "\n", "\n\t"), "\t")
165+
160166
return out
161167
}

0 commit comments

Comments
 (0)