Skip to content

Commit 06b7c55

Browse files
committed
fixed linter issues
1 parent 63423d4 commit 06b7c55

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

internal/xlist/list.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Package xlist is a copy of standard container/list but uses generics
22
// for strict checks on compile time
3-
43
package xlist
54

65
// Element is an element of a linked list.
@@ -24,6 +23,7 @@ func (e *Element[T]) Next() *Element[T] {
2423
if p := e.next; e.list != nil && p != &e.list.root {
2524
return p
2625
}
26+
2727
return nil
2828
}
2929

@@ -32,6 +32,7 @@ func (e *Element[T]) Prev() *Element[T] {
3232
if p := e.prev; e.list != nil && p != &e.list.root {
3333
return p
3434
}
35+
3536
return nil
3637
}
3738

@@ -47,6 +48,7 @@ func (l *List[T]) Init() *List[T] {
4748
l.root.next = &l.root
4849
l.root.prev = &l.root
4950
l.len = 0
51+
5052
return l
5153
}
5254

@@ -62,6 +64,7 @@ func (l *List[T]) Front() *Element[T] {
6264
if l.len == 0 {
6365
return nil
6466
}
67+
6568
return l.root.next
6669
}
6770

@@ -70,6 +73,7 @@ func (l *List[T]) Back() *Element[T] {
7073
if l.len == 0 {
7174
return nil
7275
}
76+
7377
return l.root.prev
7478
}
7579

@@ -88,6 +92,7 @@ func (l *List[T]) insert(e, at *Element[T]) *Element[T] {
8892
e.next.prev = e
8993
e.list = l
9094
l.len++
95+
9196
return e
9297
}
9398

@@ -129,18 +134,21 @@ func (l *List[T]) Remove(e *Element[T]) T {
129134
// in l or l == nil (e is a zero Element) and l.remove will crash
130135
l.remove(e)
131136
}
137+
132138
return e.Value
133139
}
134140

135141
// PushFront inserts a new element e with value v at the front of list l and returns e.
136142
func (l *List[T]) PushFront(v T) *Element[T] {
137143
l.lazyInit()
144+
138145
return l.insertValue(v, &l.root)
139146
}
140147

141148
// PushBack inserts a new element e with value v at the back of list l and returns e.
142149
func (l *List[T]) PushBack(v T) *Element[T] {
143150
l.lazyInit()
151+
144152
return l.insertValue(v, l.root.prev)
145153
}
146154

@@ -151,6 +159,7 @@ func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T] {
151159
if mark.list != l {
152160
return nil
153161
}
162+
154163
// see comment in List.Remove about initialization of l
155164
return l.insertValue(v, mark.prev)
156165
}
@@ -162,6 +171,7 @@ func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T] {
162171
if mark.list != l {
163172
return nil
164173
}
174+
165175
// see comment in List.Remove about initialization of l
166176
return l.insertValue(v, mark)
167177
}

internal/xlist/list_test.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
// Copyright 2009 The Go Authors. All rights reserved.
2-
// Use of this source code is governed by a BSD-style
3-
// license that can be found in the LICENSE file.
4-
51
package xlist
62

73
import "testing"
84

9-
func checkListLen[T comparable](t *testing.T, l *List[T], len int) bool {
10-
if n := l.Len(); n != len {
11-
t.Errorf("l.Len() = %d, want %d", n, len)
5+
func checkListLen[T comparable](t *testing.T, l *List[T], expectedLen int) bool {
6+
if n := l.Len(); n != expectedLen {
7+
t.Errorf("l.Len() = %d, want %d", n, expectedLen)
8+
129
return false
1310
}
11+
1412
return true
1513
}
1614

@@ -26,6 +24,7 @@ func checkListPointers[T comparable](t *testing.T, l *List[T], es []*Element[T])
2624
if l.root.next != nil && l.root.next != root || l.root.prev != nil && l.root.prev != root {
2725
t.Errorf("l.root.next = %p, l.root.prev = %p; both should both be nil or %p", l.root.next, l.root.prev, root)
2826
}
27+
2928
return
3029
}
3130
// len(es) > 0
@@ -292,21 +291,29 @@ func TestMove(t *testing.T) {
292291

293292
// Test PushFront, PushBack, PushFrontList, PushBackList with uninitialized List[T]
294293
func TestZeroList(t *testing.T) {
295-
var l1 = new(List[int])
296-
l1.PushFront(1)
297-
checkList(t, l1, []any{1})
298-
299-
var l2 = new(List[int])
300-
l2.PushBack(1)
301-
checkList(t, l2, []any{1})
294+
t.Run("PushFront", func(t *testing.T) {
295+
l1 := new(List[int])
296+
l1.PushFront(1)
297+
checkList(t, l1, []any{1})
298+
299+
t.Run("PushFrontList", func(t *testing.T) {
300+
l3 := new(List[int])
301+
l3.PushFrontList(l1)
302+
checkList(t, l3, []any{1})
303+
})
304+
})
302305

303-
var l3 = new(List[int])
304-
l3.PushFrontList(l1)
305-
checkList(t, l3, []any{1})
306+
t.Run("PushBack", func(t *testing.T) {
307+
l2 := new(List[int])
308+
l2.PushBack(1)
309+
checkList(t, l2, []any{1})
306310

307-
var l4 = new(List[int])
308-
l4.PushBackList(l2)
309-
checkList(t, l4, []any{1})
311+
t.Run("PushBackList", func(t *testing.T) {
312+
l4 := new(List[int])
313+
l4.PushBackList(l2)
314+
checkList(t, l4, []any{1})
315+
})
316+
})
310317
}
311318

312319
// Test that a list l is not modified when calling InsertBefore with a mark that is not an element of l.

0 commit comments

Comments
 (0)