Skip to content

Commit d3e1775

Browse files
pionbotSean-Der
authored andcommitted
Update CI configs to v0.4.7
Update lint scripts and CI configs.
1 parent e2daca4 commit d3e1775

36 files changed

+340
-215
lines changed

.golangci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,80 @@ linters-settings:
33
check-shadowing: true
44
misspell:
55
locale: US
6+
exhaustive:
7+
default-signifies-exhaustive: true
8+
9+
linters:
10+
enable:
11+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
12+
- bodyclose # checks whether HTTP response body is closed successfully
13+
- deadcode # Finds unused code
14+
- depguard # Go linter that checks if package imports are in a list of acceptable packages
15+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
16+
- dupl # Tool for code clone detection
17+
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
18+
- exhaustive # check exhaustiveness of enum switch statements
19+
- exportloopref # checks for pointers to enclosing loop variables
20+
- gci # Gci control golang package import order and make it always deterministic.
21+
- gochecknoglobals # Checks that no globals are present in Go code
22+
- gochecknoinits # Checks that no init functions are present in Go code
23+
- gocognit # Computes and checks the cognitive complexity of functions
24+
- goconst # Finds repeated strings that could be replaced by a constant
25+
- gocritic # The most opinionated Go source code linter
26+
- godox # Tool for detection of FIXME, TODO and other comment keywords
27+
- goerr113 # Golang linter to check the errors handling expressions
28+
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
29+
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
30+
- goheader # Checks is file header matches to pattern
31+
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
32+
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
33+
- 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.
34+
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
35+
- gosec # Inspects source code for security problems
36+
- gosimple # Linter for Go source code that specializes in simplifying a code
37+
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
38+
- ineffassign # Detects when assignments to existing variables are not used
39+
- misspell # Finds commonly misspelled English words in comments
40+
- nakedret # Finds naked returns in functions greater than a specified function length
41+
- noctx # noctx finds sending http request without context.Context
42+
- scopelint # Scopelint checks for unpinned variables in go programs
43+
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
44+
- structcheck # Finds unused struct fields
45+
- stylecheck # Stylecheck is a replacement for golint
46+
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
47+
- unconvert # Remove unnecessary type conversions
48+
- unparam # Reports unused function parameters
49+
- unused # Checks Go code for unused constants, variables, functions and types
50+
- varcheck # Finds unused global variables and constants
51+
- whitespace # Tool for detection of leading and trailing whitespace
52+
disable:
53+
- funlen # Tool for detection of long functions
54+
- gocyclo # Computes and checks the cyclomatic complexity of functions
55+
- godot # Check if comments end in a period
56+
- gomnd # An analyzer to detect magic numbers.
57+
- lll # Reports long lines
58+
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
59+
- nestif # Reports deeply nested if statements
60+
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
61+
- nolintlint # Reports ill-formed or insufficient nolint directives
62+
- prealloc # Finds slice declarations that could potentially be preallocated
63+
- rowserrcheck # checks whether Err of rows is checked successfully
64+
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
65+
- testpackage # linter that makes you use a separate _test package
66+
- wsl # Whitespace Linter - Forces you to use empty lines!
67+
68+
issues:
69+
exclude-rules:
70+
# Allow complex tests, better to be self contained
71+
- path: _test\.go
72+
linters:
73+
- gocognit
74+
75+
# Allow complex main function in examples
76+
- path: examples
77+
text: "of func `main` is high"
78+
linters:
79+
- gocognit
680

781
run:
882
skip-dirs-use-default: false

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
5858
* [Sidney San Martín](https://github.com/s4y)
5959
* [JooYoung Lim](https://github.com/DevRockstarZ)
6060
* [Kory Miller](https://github.com/korymiller1489)
61+
* [ZHENK](https://github.com/scorpionknifes)
6162

6263
### License
6364
MIT License - see [LICENSE](LICENSE) for full text

agent.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (a *Agent) taskLoop() {
224224
}
225225

226226
// NewAgent creates a new Agent
227-
func NewAgent(config *AgentConfig) (*Agent, error) {
227+
func NewAgent(config *AgentConfig) (*Agent, error) { //nolint:gocognit
228228
var err error
229229
if config.PortMax < config.PortMin {
230230
return nil, ErrPort
@@ -748,7 +748,7 @@ func (a *Agent) resolveAndAddMulticastCandidate(c *CandidateHost) {
748748
return
749749
}
750750

751-
ip, _, _, _ := parseAddr(src)
751+
ip, _, _, _ := parseAddr(src) //nolint:dogsled
752752
if ip == nil {
753753
a.log.Warnf("Failed to discover mDNS candidate %s: failed to parse IP", c.Address())
754754
return
@@ -1009,7 +1009,7 @@ func (a *Agent) handleInboundBindingSuccess(id [stun.TransactionIDSize]byte) (bo
10091009
}
10101010

10111011
// handleInbound processes STUN traffic from a remote candidate
1012-
func (a *Agent) handleInbound(m *stun.Message, local Candidate, remote net.Addr) {
1012+
func (a *Agent) handleInbound(m *stun.Message, local Candidate, remote net.Addr) { //nolint:gocognit
10131013
var err error
10141014
if m == nil || local == nil {
10151015
return
@@ -1074,7 +1074,6 @@ func (a *Agent) handleInbound(m *stun.Message, local Candidate, remote net.Addr)
10741074
Component: local.Component(),
10751075
RelAddr: "",
10761076
RelPort: 0,
1077-
// TODO set TCPType
10781077
}
10791078

10801079
prflxCandidate, err := NewCandidatePeerReflexive(&prflxCandidateConfig)

agent_config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const (
4242
maxBindingRequestTimeout = 4000 * time.Millisecond
4343
)
4444

45-
var (
46-
defaultCandidateTypes = []CandidateType{CandidateTypeHost, CandidateTypeServerReflexive, CandidateTypeRelay}
47-
)
45+
func defaultCandidateTypes() []CandidateType {
46+
return []CandidateType{CandidateTypeHost, CandidateTypeServerReflexive, CandidateTypeRelay}
47+
}
4848

4949
// AgentConfig collects the arguments to ice.Agent construction into
5050
// a single structure, for future-proofness of the interface
@@ -202,7 +202,7 @@ func (config *AgentConfig) initWithDefaults(a *Agent) {
202202
}
203203

204204
if config.CandidateTypes == nil || len(config.CandidateTypes) == 0 {
205-
a.candidateTypes = defaultCandidateTypes
205+
a.candidateTypes = defaultCandidateTypes()
206206
} else {
207207
a.candidateTypes = config.CandidateTypes
208208
}

agent_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ice
44

55
import (
66
"context"
7+
"errors"
78
"net"
89
"strconv"
910
"sync"
@@ -39,7 +40,6 @@ func TestPairSearch(t *testing.T) {
3940

4041
var config AgentConfig
4142
a, err := NewAgent(&config)
42-
4343
if err != nil {
4444
t.Fatalf("Error constructing ice.Agent")
4545
}
@@ -208,13 +208,13 @@ type BadAddr struct{}
208208
func (ba *BadAddr) Network() string {
209209
return "xxx"
210210
}
211+
211212
func (ba *BadAddr) String() string {
212213
return "yyy"
213214
}
214215

215216
func runAgentTest(t *testing.T, config *AgentConfig, task func(ctx context.Context, a *Agent)) {
216217
a, err := NewAgent(config)
217-
218218
if err != nil {
219219
t.Fatalf("Error constructing ice.Agent")
220220
}
@@ -255,7 +255,7 @@ func TestHandlePeerReflexive(t *testing.T) {
255255

256256
msg, err := stun.Build(stun.BindingRequest, stun.TransactionID,
257257
stun.NewUsername(a.localUfrag+":"+a.remoteUfrag),
258-
UseCandidate,
258+
UseCandidate(),
259259
AttrControlling(a.tieBreaker),
260260
PriorityAttr(local.Priority()),
261261
stun.NewShortTermIntegrity(a.localPwd),
@@ -325,7 +325,7 @@ func TestHandlePeerReflexive(t *testing.T) {
325325
runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
326326
a.selector = &controllingSelector{agent: a, log: a.log}
327327
tID := [stun.TransactionIDSize]byte{}
328-
copy(tID[:], []byte("ABC"))
328+
copy(tID[:], "ABC")
329329
a.pendingBindingRequests = []bindingRequest{
330330
{time.Now(), tID, &net.UDPAddr{}, false},
331331
}
@@ -392,7 +392,7 @@ func TestConnectivityOnStartup(t *testing.T) {
392392

393393
KeepaliveInterval := time.Hour
394394
cfg0 := &AgentConfig{
395-
NetworkTypes: supportedNetworkTypes,
395+
NetworkTypes: supportedNetworkTypes(),
396396
MulticastDNSMode: MulticastDNSModeDisabled,
397397
Net: net0,
398398

@@ -405,7 +405,7 @@ func TestConnectivityOnStartup(t *testing.T) {
405405
require.NoError(t, aAgent.OnConnectionStateChange(aNotifier))
406406

407407
cfg1 := &AgentConfig{
408-
NetworkTypes: supportedNetworkTypes,
408+
NetworkTypes: supportedNetworkTypes(),
409409
MulticastDNSMode: MulticastDNSModeDisabled,
410410
Net: net1,
411411
KeepaliveInterval: &KeepaliveInterval,
@@ -498,7 +498,7 @@ func TestConnectivityLite(t *testing.T) {
498498

499499
cfg0 := &AgentConfig{
500500
Urls: []*URL{stunServerURL},
501-
NetworkTypes: supportedNetworkTypes,
501+
NetworkTypes: supportedNetworkTypes(),
502502
MulticastDNSMode: MulticastDNSModeDisabled,
503503
Net: v.net0,
504504
}
@@ -511,7 +511,7 @@ func TestConnectivityLite(t *testing.T) {
511511
Urls: []*URL{},
512512
Lite: true,
513513
CandidateTypes: []CandidateType{CandidateTypeHost},
514-
NetworkTypes: supportedNetworkTypes,
514+
NetworkTypes: supportedNetworkTypes(),
515515
MulticastDNSMode: MulticastDNSModeDisabled,
516516
Net: v.net1,
517517
}
@@ -666,7 +666,7 @@ func TestInboundValidity(t *testing.T) {
666666

667667
remote := &net.UDPAddr{IP: net.ParseIP("172.17.0.3"), Port: 999}
668668
tID := [stun.TransactionIDSize]byte{}
669-
copy(tID[:], []byte("ABC"))
669+
copy(tID[:], "ABC")
670670
msg, err := stun.Build(stun.BindingSuccess, stun.NewTransactionIDSetter(tID),
671671
stun.NewShortTermIntegrity(a.remotePwd),
672672
stun.Fingerprint,
@@ -693,19 +693,19 @@ func TestInvalidAgentStarts(t *testing.T) {
693693
ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
694694
defer cancel()
695695

696-
if _, err = a.Dial(ctx, "", "bar"); err != nil && err != ErrRemoteUfragEmpty {
696+
if _, err = a.Dial(ctx, "", "bar"); err != nil && !errors.Is(err, ErrRemoteUfragEmpty) {
697697
t.Fatal(err)
698698
}
699699

700-
if _, err = a.Dial(ctx, "foo", ""); err != nil && err != ErrRemotePwdEmpty {
700+
if _, err = a.Dial(ctx, "foo", ""); err != nil && !errors.Is(err, ErrRemotePwdEmpty) {
701701
t.Fatal(err)
702702
}
703703

704-
if _, err = a.Dial(ctx, "foo", "bar"); err != nil && err != ErrCanceledByCaller {
704+
if _, err = a.Dial(ctx, "foo", "bar"); err != nil && !errors.Is(err, ErrCanceledByCaller) {
705705
t.Fatal(err)
706706
}
707707

708-
if _, err = a.Dial(context.TODO(), "foo", "bar"); err != nil && err != ErrMultipleStart {
708+
if _, err = a.Dial(context.TODO(), "foo", "bar"); err != nil && !errors.Is(err, ErrMultipleStart) {
709709
t.Fatal(err)
710710
}
711711

@@ -726,7 +726,7 @@ func TestConnectionStateCallback(t *testing.T) {
726726

727727
cfg := &AgentConfig{
728728
Urls: []*URL{},
729-
NetworkTypes: supportedNetworkTypes,
729+
NetworkTypes: supportedNetworkTypes(),
730730
DisconnectedTimeout: &disconnectedDuration,
731731
FailedTimeout: &failedDuration,
732732
KeepaliveInterval: &KeepaliveInterval,
@@ -786,7 +786,7 @@ func TestInvalidGather(t *testing.T) {
786786
}
787787

788788
err = a.GatherCandidates()
789-
if err != ErrNoOnCandidateHandler {
789+
if !errors.Is(err, ErrNoOnCandidateHandler) {
790790
t.Fatal("trickle GatherCandidates succeeded without OnCandidate")
791791
}
792792
assert.NoError(t, a.Close())
@@ -1161,7 +1161,7 @@ func TestInitExtIPMapping(t *testing.T) {
11611161
NAT1To1IPCandidateType: CandidateTypeHost,
11621162
CandidateTypes: []CandidateType{CandidateTypeRelay},
11631163
})
1164-
if err != ErrIneffectiveNAT1To1IPMappingHost {
1164+
if !errors.Is(err, ErrIneffectiveNAT1To1IPMappingHost) {
11651165
t.Fatalf("Unexpected error: %v", err)
11661166
}
11671167

@@ -1172,7 +1172,7 @@ func TestInitExtIPMapping(t *testing.T) {
11721172
NAT1To1IPCandidateType: CandidateTypeServerReflexive,
11731173
CandidateTypes: []CandidateType{CandidateTypeRelay},
11741174
})
1175-
if err != ErrIneffectiveNAT1To1IPMappingSrflx {
1175+
if !errors.Is(err, ErrIneffectiveNAT1To1IPMappingSrflx) {
11761176
t.Fatalf("Unexpected error: %v", err)
11771177
}
11781178

@@ -1183,7 +1183,7 @@ func TestInitExtIPMapping(t *testing.T) {
11831183
NAT1To1IPCandidateType: CandidateTypeHost,
11841184
MulticastDNSMode: MulticastDNSModeQueryAndGather,
11851185
})
1186-
if err != ErrMulticastDNSWithNAT1To1IPMapping {
1186+
if !errors.Is(err, ErrMulticastDNSWithNAT1To1IPMapping) {
11871187
t.Fatalf("Unexpected error: %v", err)
11881188
}
11891189

@@ -1192,7 +1192,7 @@ func TestInitExtIPMapping(t *testing.T) {
11921192
NAT1To1IPs: []string{"bad.2.3.4"}, // bad IP
11931193
NAT1To1IPCandidateType: CandidateTypeHost,
11941194
})
1195-
if err != ErrInvalidNAT1To1IPMapping {
1195+
if !errors.Is(err, ErrInvalidNAT1To1IPMapping) {
11961196
t.Fatalf("Unexpected error: %v", err)
11971197
}
11981198
}
@@ -1269,7 +1269,7 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) {
12691269
KeepaliveInterval := time.Duration(0)
12701270

12711271
cfg := &AgentConfig{
1272-
NetworkTypes: supportedNetworkTypes,
1272+
NetworkTypes: supportedNetworkTypes(),
12731273
DisconnectedTimeout: &oneSecond,
12741274
FailedTimeout: &oneSecond,
12751275
KeepaliveInterval: &KeepaliveInterval,
@@ -1496,7 +1496,7 @@ func TestCloseInConnectionStateCallback(t *testing.T) {
14961496

14971497
cfg := &AgentConfig{
14981498
Urls: []*URL{},
1499-
NetworkTypes: supportedNetworkTypes,
1499+
NetworkTypes: supportedNetworkTypes(),
15001500
DisconnectedTimeout: &disconnectedDuration,
15011501
FailedTimeout: &failedDuration,
15021502
KeepaliveInterval: &KeepaliveInterval,
@@ -1547,7 +1547,7 @@ func TestRunTaskInConnectionStateCallback(t *testing.T) {
15471547

15481548
cfg := &AgentConfig{
15491549
Urls: []*URL{},
1550-
NetworkTypes: supportedNetworkTypes,
1550+
NetworkTypes: supportedNetworkTypes(),
15511551
DisconnectedTimeout: &oneSecond,
15521552
FailedTimeout: &oneSecond,
15531553
KeepaliveInterval: &KeepaliveInterval,
@@ -1591,7 +1591,7 @@ func TestRunTaskInSelectedCandidatePairChangeCallback(t *testing.T) {
15911591

15921592
cfg := &AgentConfig{
15931593
Urls: []*URL{},
1594-
NetworkTypes: supportedNetworkTypes,
1594+
NetworkTypes: supportedNetworkTypes(),
15951595
DisconnectedTimeout: &oneSecond,
15961596
FailedTimeout: &oneSecond,
15971597
KeepaliveInterval: &KeepaliveInterval,

0 commit comments

Comments
 (0)