Skip to content

Commit

Permalink
Remove funlen linter (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeturki authored Jan 12, 2025
1 parent d6b6f05 commit 9d49944
Show file tree
Hide file tree
Showing 33 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ linters:
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # Forbids identifiers
- forcetypeassert # finds forced type assertions
- funlen # Tool for detection of long functions
- gci # Gci control golang package import order and make it always deterministic.
- gochecknoglobals # Checks that no globals are present in Go code
- gocognit # Computes and checks the cognitive complexity of functions
Expand Down Expand Up @@ -106,6 +105,7 @@ linters:
- whitespace # Tool for detection of leading and trailing whitespace
disable:
- depguard # Go linter that checks if package imports are in a list of acceptable packages
- funlen # Tool for detection of long functions
- gochecknoinits # Checks that no init functions are present in Go code
- 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.
- interfacebloat # A linter that checks length of interface.
Expand Down Expand Up @@ -135,4 +135,4 @@ issues:
# Allow forbidden identifiers in CLI commands
- path: cmd
linters:
- forbidigo
- forbidigo
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (c *Client) SendBindingRequest() (net.Addr, error) {
return c.SendBindingRequestTo(c.stunServerAddr)
}

func (c *Client) sendAllocateRequest(protocol proto.Protocol) ( // nolint:cyclop,funlen
func (c *Client) sendAllocateRequest(protocol proto.Protocol) ( //nolint:cyclop
proto.RelayedAddress,
proto.Lifetime,
stun.Nonce,
Expand Down Expand Up @@ -507,7 +507,7 @@ func (c *Client) HandleInbound(data []byte, from net.Addr) (bool, error) {
return false, nil
}

func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error { // nolint:cyclop,funlen
func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error { //nolint:cyclop
raw := make([]byte, len(data))
copy(raw, data)

Expand Down
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func createListeningTestClientWithSTUNServ(t *testing.T, loggerFactory logging.L
return c, conn, true
}

func TestClientWithSTUN(t *testing.T) { // nolint:funlen
func TestClientWithSTUN(t *testing.T) {
loggerFactory := logging.NewDefaultLoggerFactory()
log := loggerFactory.NewLogger("test")

Expand Down Expand Up @@ -198,7 +198,7 @@ func TestClientNonceExpiration(t *testing.T) {
}

// Create a TCP-based allocation and verify allocation can be created.
func TestTCPClient(t *testing.T) { // nolint:funlen
func TestTCPClient(t *testing.T) {
// Setup server
tcpListener, err := net.Listen("tcp4", "0.0.0.0:13478") //nolint: gosec
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-client/tcp-alloc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func setupSignalingChannel(addrCh chan string, signaling bool, relayAddr string)
}
}

func main() { // nolint:funlen,cyclop
func main() { //nolint:cyclop
host := flag.String("host", "", "TURN Server name.")
port := flag.Int("port", 3478, "Listening port.")
user := flag.String("user", "", "A pair of username and password (e.g. \"user=pass\")")
Expand Down
4 changes: 2 additions & 2 deletions examples/turn-client/tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen,cyclop
func main() { //nolint:cyclop
host := flag.String("host", "", "TURN Server name.")
port := flag.Int("port", 3478, "Listening port.")
user := flag.String("user", "", "A pair of username and password (e.g. \"user=pass\")")
Expand Down Expand Up @@ -92,7 +92,7 @@ func main() { // nolint:funlen,cyclop
}
}

func doPingTest(client *turn.Client, relayConn net.PacketConn) error { // nolint:cyclop,funlen
func doPingTest(client *turn.Client, relayConn net.PacketConn) error { //nolint:cyclop
// Send BindingRequest to learn our external IP
mappedAddr, err := client.SendBindingRequest()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/turn-client/udp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen,cyclop
func main() { //nolint:cyclop
host := flag.String("host", "", "TURN Server name.")
port := flag.Int("port", 3478, "Listening port.")
user := flag.String("user", "", "A pair of username and password (e.g. \"user=pass\")")
Expand Down Expand Up @@ -96,7 +96,7 @@ func main() { // nolint:funlen,cyclop
}
}

func doPingTest(client *turn.Client, relayConn net.PacketConn) error { // nolint:cyclop,funlen
func doPingTest(client *turn.Client, relayConn net.PacketConn) error { //nolint:cyclop
// Send BindingRequest to learn our external IP
mappedAddr, err := client.SendBindingRequest()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/add-software-attribute/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *attributeAdder) WriteTo(payload []byte, addr net.Addr) (n int, err erro
return s.PacketConn.WriteTo(payload, addr)
}

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/log/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *stunLogger) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
return
}

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/perm-filter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/port-range/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/simple-multithreaded/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"golang.org/x/sys/unix"
)

func main() { // nolint:funlen,cyclop
func main() { //nolint:cyclop
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 3478, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion examples/turn-server/tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pion/turn/v4"
)

func main() { // nolint:funlen
func main() {
publicIP := flag.String("public-ip", "", "IP Address that TURN can be contacted by.")
port := flag.Int("port", 5349, "Listening port.")
users := flag.String("users", "", "List of username and password (e.g. \"user=pass,user=pass\")")
Expand Down
2 changes: 1 addition & 1 deletion internal/allocation/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func subTestAllocationClose(t *testing.T) {
assert.True(t, isClose(alloc.RelaySocket), "should be closed")
}

func subTestPacketHandler(t *testing.T) { // nolint:funlen
func subTestPacketHandler(t *testing.T) {
t.Helper()

network := "udp"
Expand Down
2 changes: 1 addition & 1 deletion internal/client/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestBindingManager(t *testing.T) { // nolint:funlen
func TestBindingManager(t *testing.T) {
t.Run("number assignment", func(t *testing.T) {
bm := newBindingManager()
var chanNum uint16
Expand Down
2 changes: 1 addition & 1 deletion internal/client/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPermission(t *testing.T) {
})
}

func TestPermissionMap(t *testing.T) { // nolint:funlen
func TestPermissionMap(t *testing.T) {
t.Run("Basic operations", func(t *testing.T) {
pm := newPermissionMap()
assert.NotNil(t, pm)
Expand Down
2 changes: 1 addition & 1 deletion internal/client/tcp_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (a *TCPAllocation) DialTCPWithConn(conn net.Conn, _ string, rAddr *net.TCPA
}

// BindConnection associates the provided connection.
func (a *TCPAllocation) BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error { // nolint:cyclop,funlen
func (a *TCPAllocation) BindConnection(dataConn *TCPConn, cid proto.ConnectionID) error { //nolint:cyclop
msg, err := stun.Build(
stun.TransactionID,
stun.NewType(stun.MethodConnectionBind, stun.ClassRequest),
Expand Down
2 changes: 1 addition & 1 deletion internal/client/tcp_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c dummyTCPConn) Read(b []byte) (int, error) {
return len(msg.Raw), nil
}

func TestTCPConn(t *testing.T) { //nolint:funlen
func TestTCPConn(t *testing.T) {
t.Run("Connect()", func(t *testing.T) {
var cid proto.ConnectionID = 5
client := &mockClient{
Expand Down
2 changes: 1 addition & 1 deletion internal/client/udp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (a *allocation) createPermission(perm *permission, addr net.Addr) error {
// an Error with Timeout() == true after a fixed time limit;
// see SetDeadline and SetWriteDeadline.
// On packet-oriented connections, write timeouts are rare.
func (c *UDPConn) WriteTo(payload []byte, addr net.Addr) (int, error) { //nolint:gocognit,cyclop,funlen
func (c *UDPConn) WriteTo(payload []byte, addr net.Addr) (int, error) { //nolint:gocognit,cyclop
var err error
_, ok := addr.(*net.UDPAddr)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/udp_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestUDPConn(t *testing.T) { //nolint:funlen
func TestUDPConn(t *testing.T) {
t.Run("bind()", func(t *testing.T) {
client := &mockClient{
performTransaction: func(*stun.Message, net.Addr, bool) (TransactionResult, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/chandata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestChannelData_Encode(t *testing.T) {
}
}

func TestChannelData_Equal(t *testing.T) { // nolint:funlen
func TestChannelData_Equal(t *testing.T) {
for _, tc := range []struct {
name string
a, b *ChannelData
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/chann_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func BenchmarkChannelNumber(b *testing.B) {
})
}

func TestChannelNumber(t *testing.T) { // nolint:cyclop,funlen
func TestChannelNumber(t *testing.T) { //nolint:cyclop
t.Run("String", func(t *testing.T) {
n := ChannelNumber(112)
if n.String() != "112" {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/evenport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestEvenPort(t *testing.T) { // nolint:cyclop,funlen
func TestEvenPort(t *testing.T) { //nolint:cyclop
t.Run("String", func(t *testing.T) {
p := EvenPort{}
if p.String() != "reserve: false" {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/lifetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func BenchmarkLifetime(b *testing.B) {
})
}

func TestLifetime(t *testing.T) { // nolint:cyclop,funlen
func TestLifetime(t *testing.T) { //nolint:cyclop
t.Run("String", func(t *testing.T) {
l := Lifetime{time.Second * 10}
if l.String() != "10s" {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/reqfamily_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pion/stun/v3"
)

func TestRequestedAddressFamily(t *testing.T) { // nolint:cyclop,funlen
func TestRequestedAddressFamily(t *testing.T) { //nolint:cyclop
t.Run("String", func(t *testing.T) {
if RequestedFamilyIPv4.String() != "IPv4" {
t.Errorf("bad string %q, expected %q", RequestedFamilyIPv4,
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/reqtrans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pion/stun/v3"
)

func TestRequestedTransport(t *testing.T) { // nolint:cyclop,funlen
func TestRequestedTransport(t *testing.T) { //nolint:cyclop
t.Run("String", func(t *testing.T) {
transAttr := RequestedTransport{
Protocol: ProtoUDP,
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/rsrvtoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pion/stun/v3"
)

func TestReservationToken(t *testing.T) { // nolint:cyclop,funlen
func TestReservationToken(t *testing.T) { //nolint:cyclop
t.Run("NoAlloc", func(t *testing.T) {
stunMsg := &stun.Message{}
tok := make([]byte, 8)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/turn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const runesAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

// See: https://tools.ietf.org/html/rfc5766#section-6.2
// .
func handleAllocateRequest(req Request, stunMsg *stun.Message) error { // nolint:cyclop,funlen
func handleAllocateRequest(req Request, stunMsg *stun.Message) error { //nolint:cyclop
req.Log.Debugf("Received AllocateRequest from %s", req.SrcAddr)

// 1. The server MUST require that the request be authenticated. This
Expand Down
2 changes: 1 addition & 1 deletion internal/server/turn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestAllocationLifeTime(t *testing.T) { // nolint:funlen
func TestAllocationLifeTime(t *testing.T) {
t.Run("Parsing", func(t *testing.T) {
lifetime := proto.Lifetime{
Duration: 5 * time.Second,
Expand Down
2 changes: 1 addition & 1 deletion internal/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func buildMsg(
return append([]stun.Setter{&stun.Message{TransactionID: transactionID}, msgType}, additional...)
}

func authenticateRequest(req Request, stunMsg *stun.Message, callingMethod stun.Method) ( // nolint:funlen
func authenticateRequest(req Request, stunMsg *stun.Message, callingMethod stun.Method) (
stun.MessageIntegrity,
bool,
error,
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Server struct {
}

// NewServer creates the Pion TURN server.
func NewServer(config ServerConfig) (*Server, error) { // nolint:gocognit,cyclop,funlen
func NewServer(config ServerConfig) (*Server, error) { //nolint:gocognit,cyclop
if err := config.validate(); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestServer(t *testing.T) { // nolint:funlen,maintidx
func TestServer(t *testing.T) { //nolint:maintidx
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

Expand Down Expand Up @@ -381,7 +381,7 @@ func (v *VNet) Close() error {
return v.wan.Stop()
}

func buildVNet() (*VNet, error) { // nolint:cyclop,funlen
func buildVNet() (*VNet, error) { //nolint:cyclop
loggerFactory := logging.NewDefaultLoggerFactory()

// WAN
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestSTUNOnly(t *testing.T) {
assert.Equal(t, err.Error(), "Allocate error response (error 400: )")
}

func RunBenchmarkServer(b *testing.B, clientNum int) { // nolint:cyclop,funlen
func RunBenchmarkServer(b *testing.B, clientNum int) { //nolint:cyclop
b.Helper()

loggerFactory := logging.NewDefaultLoggerFactory()
Expand Down

0 comments on commit 9d49944

Please sign in to comment.