From 9d4994410386c5284d892f23fbf666f235515249 Mon Sep 17 00:00:00 2001 From: Joe Turki Date: Sun, 12 Jan 2025 02:49:05 -0600 Subject: [PATCH] Remove funlen linter (#433) --- .golangci.yml | 4 ++-- client.go | 4 ++-- client_test.go | 4 ++-- examples/turn-client/tcp-alloc/main.go | 2 +- examples/turn-client/tcp/main.go | 4 ++-- examples/turn-client/udp/main.go | 4 ++-- examples/turn-server/add-software-attribute/main.go | 2 +- examples/turn-server/log/main.go | 2 +- examples/turn-server/perm-filter/main.go | 2 +- examples/turn-server/port-range/main.go | 2 +- examples/turn-server/simple-multithreaded/main.go | 2 +- examples/turn-server/simple/main.go | 2 +- examples/turn-server/tcp/main.go | 2 +- examples/turn-server/tls/main.go | 2 +- internal/allocation/allocation_test.go | 2 +- internal/client/binding_test.go | 2 +- internal/client/permission_test.go | 2 +- internal/client/tcp_alloc.go | 2 +- internal/client/tcp_conn_test.go | 2 +- internal/client/udp_conn.go | 2 +- internal/client/udp_conn_test.go | 2 +- internal/proto/chandata_test.go | 2 +- internal/proto/chann_test.go | 2 +- internal/proto/evenport_test.go | 2 +- internal/proto/lifetime_test.go | 2 +- internal/proto/reqfamily_test.go | 2 +- internal/proto/reqtrans_test.go | 2 +- internal/proto/rsrvtoken_test.go | 2 +- internal/server/turn.go | 2 +- internal/server/turn_test.go | 2 +- internal/server/util.go | 2 +- server.go | 2 +- server_test.go | 6 +++--- 33 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 50211be0..06650621 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -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. @@ -135,4 +135,4 @@ issues: # Allow forbidden identifiers in CLI commands - path: cmd linters: - - forbidigo + - forbidigo \ No newline at end of file diff --git a/client.go b/client.go index 328324e8..39a78997 100644 --- a/client.go +++ b/client.go @@ -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, @@ -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) diff --git a/client_test.go b/client_test.go index 924e5767..2c17a900 100644 --- a/client_test.go +++ b/client_test.go @@ -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") @@ -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) diff --git a/examples/turn-client/tcp-alloc/main.go b/examples/turn-client/tcp-alloc/main.go index ea3c0da3..c0a97f16 100644 --- a/examples/turn-client/tcp-alloc/main.go +++ b/examples/turn-client/tcp-alloc/main.go @@ -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\")") diff --git a/examples/turn-client/tcp/main.go b/examples/turn-client/tcp/main.go index 80a55bbd..23486787 100644 --- a/examples/turn-client/tcp/main.go +++ b/examples/turn-client/tcp/main.go @@ -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\")") @@ -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 { diff --git a/examples/turn-client/udp/main.go b/examples/turn-client/udp/main.go index 46f8c68a..91da14d4 100644 --- a/examples/turn-client/udp/main.go +++ b/examples/turn-client/udp/main.go @@ -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\")") @@ -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 { diff --git a/examples/turn-server/add-software-attribute/main.go b/examples/turn-server/add-software-attribute/main.go index 66f90494..344cdf2b 100644 --- a/examples/turn-server/add-software-attribute/main.go +++ b/examples/turn-server/add-software-attribute/main.go @@ -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\")") diff --git a/examples/turn-server/log/main.go b/examples/turn-server/log/main.go index 989112f3..f9212a83 100644 --- a/examples/turn-server/log/main.go +++ b/examples/turn-server/log/main.go @@ -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\")") diff --git a/examples/turn-server/perm-filter/main.go b/examples/turn-server/perm-filter/main.go index 2554594a..9496aec6 100644 --- a/examples/turn-server/perm-filter/main.go +++ b/examples/turn-server/perm-filter/main.go @@ -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\")") diff --git a/examples/turn-server/port-range/main.go b/examples/turn-server/port-range/main.go index d0399960..28864487 100644 --- a/examples/turn-server/port-range/main.go +++ b/examples/turn-server/port-range/main.go @@ -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\")") diff --git a/examples/turn-server/simple-multithreaded/main.go b/examples/turn-server/simple-multithreaded/main.go index dd477afd..2e188884 100644 --- a/examples/turn-server/simple-multithreaded/main.go +++ b/examples/turn-server/simple-multithreaded/main.go @@ -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\")") diff --git a/examples/turn-server/simple/main.go b/examples/turn-server/simple/main.go index b4babd0a..bf3ea524 100644 --- a/examples/turn-server/simple/main.go +++ b/examples/turn-server/simple/main.go @@ -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\")") diff --git a/examples/turn-server/tcp/main.go b/examples/turn-server/tcp/main.go index 0c3a96ef..7663836b 100644 --- a/examples/turn-server/tcp/main.go +++ b/examples/turn-server/tcp/main.go @@ -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\")") diff --git a/examples/turn-server/tls/main.go b/examples/turn-server/tls/main.go index 76870eb3..96a5506a 100644 --- a/examples/turn-server/tls/main.go +++ b/examples/turn-server/tls/main.go @@ -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\")") diff --git a/internal/allocation/allocation_test.go b/internal/allocation/allocation_test.go index 74068394..b2c67717 100644 --- a/internal/allocation/allocation_test.go +++ b/internal/allocation/allocation_test.go @@ -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" diff --git a/internal/client/binding_test.go b/internal/client/binding_test.go index 4d9f18a5..f437626c 100644 --- a/internal/client/binding_test.go +++ b/internal/client/binding_test.go @@ -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 diff --git a/internal/client/permission_test.go b/internal/client/permission_test.go index 5c617c96..edcdbc60 100644 --- a/internal/client/permission_test.go +++ b/internal/client/permission_test.go @@ -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) diff --git a/internal/client/tcp_alloc.go b/internal/client/tcp_alloc.go index e2ca30d8..5b72fe80 100644 --- a/internal/client/tcp_alloc.go +++ b/internal/client/tcp_alloc.go @@ -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), diff --git a/internal/client/tcp_conn_test.go b/internal/client/tcp_conn_test.go index 88e022e1..e3e4bdc3 100644 --- a/internal/client/tcp_conn_test.go +++ b/internal/client/tcp_conn_test.go @@ -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{ diff --git a/internal/client/udp_conn.go b/internal/client/udp_conn.go index f423d767..2a6af1bf 100644 --- a/internal/client/udp_conn.go +++ b/internal/client/udp_conn.go @@ -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 { diff --git a/internal/client/udp_conn_test.go b/internal/client/udp_conn_test.go index 0b01315a..889ffe4b 100644 --- a/internal/client/udp_conn_test.go +++ b/internal/client/udp_conn_test.go @@ -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) { diff --git a/internal/proto/chandata_test.go b/internal/proto/chandata_test.go index ad01f994..e3e03da5 100644 --- a/internal/proto/chandata_test.go +++ b/internal/proto/chandata_test.go @@ -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 diff --git a/internal/proto/chann_test.go b/internal/proto/chann_test.go index ebbc1fb4..e4f80423 100644 --- a/internal/proto/chann_test.go +++ b/internal/proto/chann_test.go @@ -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" { diff --git a/internal/proto/evenport_test.go b/internal/proto/evenport_test.go index 2e5abcaf..fb641fe6 100644 --- a/internal/proto/evenport_test.go +++ b/internal/proto/evenport_test.go @@ -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" { diff --git a/internal/proto/lifetime_test.go b/internal/proto/lifetime_test.go index 08afc005..83002090 100644 --- a/internal/proto/lifetime_test.go +++ b/internal/proto/lifetime_test.go @@ -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" { diff --git a/internal/proto/reqfamily_test.go b/internal/proto/reqfamily_test.go index 63492e3c..36737244 100644 --- a/internal/proto/reqfamily_test.go +++ b/internal/proto/reqfamily_test.go @@ -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, diff --git a/internal/proto/reqtrans_test.go b/internal/proto/reqtrans_test.go index 2a78f728..d024706a 100644 --- a/internal/proto/reqtrans_test.go +++ b/internal/proto/reqtrans_test.go @@ -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, diff --git a/internal/proto/rsrvtoken_test.go b/internal/proto/rsrvtoken_test.go index 64fdff47..14dcb5ef 100644 --- a/internal/proto/rsrvtoken_test.go +++ b/internal/proto/rsrvtoken_test.go @@ -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) diff --git a/internal/server/turn.go b/internal/server/turn.go index e49beb95..d20c5dc5 100644 --- a/internal/server/turn.go +++ b/internal/server/turn.go @@ -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 diff --git a/internal/server/turn_test.go b/internal/server/turn_test.go index 31a648da..18e0c47d 100644 --- a/internal/server/turn_test.go +++ b/internal/server/turn_test.go @@ -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, diff --git a/internal/server/util.go b/internal/server/util.go index d3a63f33..a16bf439 100644 --- a/internal/server/util.go +++ b/internal/server/util.go @@ -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, diff --git a/server.go b/server.go index 90fa48cf..57b7a3b8 100644 --- a/server.go +++ b/server.go @@ -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 } diff --git a/server_test.go b/server_test.go index de6cb62d..0833cae2 100644 --- a/server_test.go +++ b/server_test.go @@ -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() @@ -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 @@ -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()