Skip to content

Commit 1b92b5c

Browse files
authored
lint: enable 7 more linters (#686)
* lint: enable and fix perfsprint issues * lint: enable and fix nolintlint issues * lint: enable and fix godot issues * lint: enable and fix thelper issues * lint: enable and fix tparallel issues * lint: enable and fix paralleltest issues * lint: enable and fix predeclared issues
1 parent 2911f93 commit 1b92b5c

22 files changed

+301
-231
lines changed

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ linters:
3030
# - wsl_v5
3131
- testifylint
3232
- whitespace
33+
- perfsprint
34+
- nolintlint
35+
- godot
36+
- thelper
37+
- tparallel
38+
- paralleltest
39+
- predeclared
3340

3441
# disable noisy/controversial ones which you might enable later
3542
disable:

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ duration := lo.Duration0(func() {
21432143

21442144
err, duration := lo.Duration1(func() error {
21452145
// very long job
2146-
return fmt.Errorf("an error")
2146+
return errors.New("an error")
21472147
})
21482148
// an error
21492149
// 3s
@@ -3752,7 +3752,7 @@ iter, err := lo.Attempt(42, func(i int) error {
37523752
return nil
37533753
}
37543754

3755-
return fmt.Errorf("failed")
3755+
return errors.New("failed")
37563756
})
37573757
// 6
37583758
// nil
@@ -3762,14 +3762,14 @@ iter, err := lo.Attempt(2, func(i int) error {
37623762
return nil
37633763
}
37643764

3765-
return fmt.Errorf("failed")
3765+
return errors.New("failed")
37663766
})
37673767
// 2
37683768
// error "failed"
37693769

37703770
iter, err := lo.Attempt(0, func(i int) error {
37713771
if i < 42 {
3772-
return fmt.Errorf("failed")
3772+
return errors.New("failed")
37733773
}
37743774

37753775
return nil
@@ -3794,7 +3794,7 @@ iter, duration, err := lo.AttemptWithDelay(5, 2*time.Second, func(i int, duratio
37943794
return nil
37953795
}
37963796

3797-
return fmt.Errorf("failed")
3797+
return errors.New("failed")
37983798
})
37993799
// 3
38003800
// ~ 4 seconds
@@ -4045,7 +4045,7 @@ transaction := NewTransaction().
40454045
fmt.Println("step 3")
40464046

40474047
if true {
4048-
return state, fmt.Errorf("error")
4048+
return state, errors.New("error")
40494049
}
40504050

40514051
return state + 42, nil
@@ -4239,7 +4239,7 @@ ok := lo.Try(func() error {
42394239
// true
42404240

42414241
ok := lo.Try(func() error {
4242-
return fmt.Errorf("error")
4242+
return errors.New("error")
42434243
})
42444244
// false
42454245
```
@@ -4279,7 +4279,7 @@ str, ok := lo.TryOr(func() error {
42794279
// true
42804280

42814281
str, ok := lo.TryOr(func() error {
4282-
return "hello", fmt.Errorf("error")
4282+
return "hello", errors.New("error")
42834283
}, "world")
42844284
// world
42854285
// false

channel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func DispatchingStrategyFirst[T any](msg T, index uint64, channels []<-chan T) i
145145
func DispatchingStrategyLeast[T any](msg T, index uint64, channels []<-chan T) int {
146146
seq := Range(len(channels))
147147

148-
return MinBy(seq, func(item int, min int) bool {
149-
return len(channels[item]) < len(channels[min])
148+
return MinBy(seq, func(item int, mIn int) bool {
149+
return len(channels[item]) < len(channels[mIn])
150150
})
151151
}
152152

@@ -156,8 +156,8 @@ func DispatchingStrategyLeast[T any](msg T, index uint64, channels []<-chan T) i
156156
func DispatchingStrategyMost[T any](msg T, index uint64, channels []<-chan T) int {
157157
seq := Range(len(channels))
158158

159-
return MaxBy(seq, func(item int, max int) bool {
160-
return len(channels[item]) > len(channels[max]) && channelIsNotFull(channels[item])
159+
return MaxBy(seq, func(item int, mAx int) bool {
160+
return len(channels[item]) > len(channels[mAx]) && channelIsNotFull(channels[item])
161161
})
162162
}
163163

channel_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestDispatchingStrategyRoundRobin(t *testing.T) {
113113
}
114114

115115
func TestDispatchingStrategyRandom(t *testing.T) {
116+
t.Parallel()
116117
testWithTimeout(t, 10*time.Millisecond)
117118
is := assert.New(t)
118119

condition_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestTernary(t *testing.T) {
1818
}
1919

2020
func TestTernaryF(t *testing.T) {
21+
t.Parallel()
2122
is := assert.New(t)
2223

2324
result1 := TernaryF(true, func() string { return "a" }, func() string { return "b" })

errors_example_test.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lo
22

33
import (
4+
"errors"
45
"fmt"
56
)
67

@@ -31,10 +32,10 @@ func ExampleMust() {
3132
Must(cb())
3233

3334
// will panic
34-
Must(42, fmt.Errorf("my error"))
35+
Must(42, errors.New("my error"))
3536

3637
// will panic with error message
37-
Must(42, fmt.Errorf("world"), "hello")
38+
Must(42, errors.New("world"), "hello")
3839
}
3940

4041
func ExampleMust0() {
@@ -46,10 +47,10 @@ func ExampleMust0() {
4647
Must0(nil)
4748

4849
// will panic
49-
Must0(fmt.Errorf("my error"))
50+
Must0(errors.New("my error"))
5051

5152
// will panic with error message
52-
Must0(fmt.Errorf("world"), "hello")
53+
Must0(errors.New("world"), "hello")
5354
}
5455

5556
func ExampleMust1() {
@@ -67,10 +68,10 @@ func ExampleMust1() {
6768
Must1(cb())
6869

6970
// will panic
70-
Must1(42, fmt.Errorf("my error"))
71+
Must1(42, errors.New("my error"))
7172

7273
// will panic with error message
73-
Must1(42, fmt.Errorf("world"), "hello")
74+
Must1(42, errors.New("world"), "hello")
7475
}
7576

7677
func ExampleMust2() {
@@ -82,10 +83,10 @@ func ExampleMust2() {
8283
Must2(42, "hello", nil)
8384

8485
// will panic
85-
Must2(42, "hello", fmt.Errorf("my error"))
86+
Must2(42, "hello", errors.New("my error"))
8687

8788
// will panic with error message
88-
Must2(42, "hello", fmt.Errorf("world"), "hello")
89+
Must2(42, "hello", errors.New("world"), "hello")
8990
}
9091

9192
func ExampleMust3() {
@@ -97,10 +98,10 @@ func ExampleMust3() {
9798
Must3(42, "hello", 4.2, nil)
9899

99100
// will panic
100-
Must3(42, "hello", 4.2, fmt.Errorf("my error"))
101+
Must3(42, "hello", 4.2, errors.New("my error"))
101102

102103
// will panic with error message
103-
Must3(42, "hello", 4.2, fmt.Errorf("world"), "hello")
104+
Must3(42, "hello", 4.2, errors.New("world"), "hello")
104105
}
105106

106107
func ExampleMust4() {
@@ -112,10 +113,10 @@ func ExampleMust4() {
112113
Must4(42, "hello", 4.2, true, nil)
113114

114115
// will panic
115-
Must4(42, "hello", 4.2, true, fmt.Errorf("my error"))
116+
Must4(42, "hello", 4.2, true, errors.New("my error"))
116117

117118
// will panic with error message
118-
Must4(42, "hello", 4.2, true, fmt.Errorf("world"), "hello")
119+
Must4(42, "hello", 4.2, true, errors.New("world"), "hello")
119120
}
120121

121122
func ExampleMust5() {
@@ -127,10 +128,10 @@ func ExampleMust5() {
127128
Must5(42, "hello", 4.2, true, foo{}, nil)
128129

129130
// will panic
130-
Must5(42, "hello", 4.2, true, foo{}, fmt.Errorf("my error"))
131+
Must5(42, "hello", 4.2, true, foo{}, errors.New("my error"))
131132

132133
// will panic with error message
133-
Must5(42, "hello", 4.2, true, foo{}, fmt.Errorf("world"), "hello")
134+
Must5(42, "hello", 4.2, true, foo{}, errors.New("world"), "hello")
134135
}
135136

136137
func ExampleMust6() {
@@ -142,18 +143,18 @@ func ExampleMust6() {
142143
Must5(42, "hello", 4.2, true, foo{}, "foobar", nil)
143144

144145
// will panic
145-
Must5(42, "hello", 4.2, true, foo{}, "foobar", fmt.Errorf("my error"))
146+
Must5(42, "hello", 4.2, true, foo{}, "foobar", errors.New("my error"))
146147

147148
// will panic with error message
148-
Must5(42, "hello", 4.2, true, foo{}, "foobar", fmt.Errorf("world"), "hello")
149+
Must5(42, "hello", 4.2, true, foo{}, "foobar", errors.New("world"), "hello")
149150
}
150151

151152
func ExampleTry() {
152153
ok1 := Try(func() error {
153154
return nil
154155
})
155156
ok2 := Try(func() error {
156-
return fmt.Errorf("my error")
157+
return errors.New("my error")
157158
})
158159
ok3 := Try(func() error {
159160
panic("my error")
@@ -173,7 +174,7 @@ func ExampleTry1() {
173174
return nil
174175
})
175176
ok2 := Try1(func() error {
176-
return fmt.Errorf("my error")
177+
return errors.New("my error")
177178
})
178179
ok3 := Try1(func() error {
179180
panic("my error")
@@ -193,7 +194,7 @@ func ExampleTry2() {
193194
return 42, nil
194195
})
195196
ok2 := Try2(func() (int, error) {
196-
return 42, fmt.Errorf("my error")
197+
return 42, errors.New("my error")
197198
})
198199
ok3 := Try2(func() (int, error) {
199200
panic("my error")
@@ -213,7 +214,7 @@ func ExampleTry3() {
213214
return 42, "foobar", nil
214215
})
215216
ok2 := Try3(func() (int, string, error) {
216-
return 42, "foobar", fmt.Errorf("my error")
217+
return 42, "foobar", errors.New("my error")
217218
})
218219
ok3 := Try3(func() (int, string, error) {
219220
panic("my error")
@@ -233,7 +234,7 @@ func ExampleTry4() {
233234
return 42, "foobar", 4.2, nil
234235
})
235236
ok2 := Try4(func() (int, string, float64, error) {
236-
return 42, "foobar", 4.2, fmt.Errorf("my error")
237+
return 42, "foobar", 4.2, errors.New("my error")
237238
})
238239
ok3 := Try4(func() (int, string, float64, error) {
239240
panic("my error")
@@ -253,7 +254,7 @@ func ExampleTry5() {
253254
return 42, "foobar", 4.2, true, nil
254255
})
255256
ok2 := Try5(func() (int, string, float64, bool, error) {
256-
return 42, "foobar", 4.2, true, fmt.Errorf("my error")
257+
return 42, "foobar", 4.2, true, errors.New("my error")
257258
})
258259
ok3 := Try5(func() (int, string, float64, bool, error) {
259260
panic("my error")
@@ -273,7 +274,7 @@ func ExampleTry6() {
273274
return 42, "foobar", 4.2, true, foo{}, nil
274275
})
275276
ok2 := Try6(func() (int, string, float64, bool, foo, error) {
276-
return 42, "foobar", 4.2, true, foo{}, fmt.Errorf("my error")
277+
return 42, "foobar", 4.2, true, foo{}, errors.New("my error")
277278
})
278279
ok3 := Try6(func() (int, string, float64, bool, foo, error) {
279280
panic("my error")
@@ -293,7 +294,7 @@ func ExampleTryOr() {
293294
return 42, nil
294295
}, 21)
295296
value2, ok2 := TryOr(func() (int, error) {
296-
return 42, fmt.Errorf("my error")
297+
return 42, errors.New("my error")
297298
}, 21)
298299
value3, ok3 := TryOr(func() (int, error) {
299300
panic("my error")
@@ -313,7 +314,7 @@ func ExampleTryOr1() {
313314
return 42, nil
314315
}, 21)
315316
value2, ok2 := TryOr1(func() (int, error) {
316-
return 42, fmt.Errorf("my error")
317+
return 42, errors.New("my error")
317318
}, 21)
318319
value3, ok3 := TryOr1(func() (int, error) {
319320
panic("my error")
@@ -378,7 +379,7 @@ func ExampleTryWithErrorValue() {
378379
return nil
379380
})
380381
err2, ok2 := TryWithErrorValue(func() error {
381-
return fmt.Errorf("my error")
382+
return errors.New("my error")
382383
})
383384
err3, ok3 := TryWithErrorValue(func() error {
384385
panic("my error")

errors_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package lo
22

33
import (
44
"errors"
5-
"fmt"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
98
)
109

1110
func TestValidate(t *testing.T) {
11+
t.Parallel()
1212
is := assert.New(t)
1313

1414
slice := []string{"a"}
@@ -264,7 +264,7 @@ func TestTry(t *testing.T) {
264264
return nil
265265
}))
266266
is.False(Try(func() error {
267-
return fmt.Errorf("fail")
267+
return errors.New("fail")
268268
}))
269269
}
270270

@@ -587,7 +587,7 @@ func TestErrorsAs(t *testing.T) {
587587
t.Parallel()
588588
is := assert.New(t)
589589

590-
err, ok := ErrorsAs[*internalError](fmt.Errorf("hello world"))
590+
err, ok := ErrorsAs[*internalError](errors.New("hello world"))
591591
is.False(ok)
592592
is.Nil(err)
593593

0 commit comments

Comments
 (0)