From 21395c58ffa535349fee731070bfbedb7f972c4a Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Sat, 2 Dec 2023 15:14:23 +0100 Subject: [PATCH] style: linting IsNil --- type_manipulation.go | 12 ++++++------ type_manipulation_test.go | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/type_manipulation.go b/type_manipulation.go index ac31c0f5..ec787189 100644 --- a/type_manipulation.go +++ b/type_manipulation.go @@ -2,17 +2,17 @@ package lo import "reflect" -// ToPtr returns a pointer copy of value. -func ToPtr[T any](x T) *T { - return &x -} - // IsNil checks if a value is nil or if it's a reference type with a nil underlying value. func IsNil(x any) bool { - defer func() { recover() }() + defer func() { recover() }() // nolint:errcheck return x == nil || reflect.ValueOf(x).IsNil() } +// ToPtr returns a pointer copy of value. +func ToPtr[T any](x T) *T { + return &x +} + // EmptyableToPtr returns a pointer copy of value if it's nonzero. // Otherwise, returns nil pointer. func EmptyableToPtr[T any](x T) *T { diff --git a/type_manipulation_test.go b/type_manipulation_test.go index ee4fa42e..4ed6cb57 100644 --- a/type_manipulation_test.go +++ b/type_manipulation_test.go @@ -6,15 +6,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestToPtr(t *testing.T) { - t.Parallel() - is := assert.New(t) - - result1 := ToPtr([]int{1, 2}) - - is.Equal(*result1, []int{1, 2}) -} - func TestIsNil(t *testing.T) { t.Parallel() is := assert.New(t) @@ -36,7 +27,16 @@ func TestIsNil(t *testing.T) { var ifaceWithNilValue interface{} = (*string)(nil) is.True(IsNil(ifaceWithNilValue)) - is.True(ifaceWithNilValue != nil) + is.False(ifaceWithNilValue == nil) // nolint:staticcheck +} + +func TestToPtr(t *testing.T) { + t.Parallel() + is := assert.New(t) + + result1 := ToPtr([]int{1, 2}) + + is.Equal(*result1, []int{1, 2}) } func TestEmptyableToPtr(t *testing.T) {