@@ -69,22 +69,24 @@ https://golangci-lint.run/usage/linters/#testifylint
69
69
70
70
| Name | Enabled By Default | Autofix |
71
71
| -----------------------------------------------------| --------------------| ---------|
72
- | [ blank-import] ( #blank-import ) | ✅ | ❌ |
73
- | [ bool-compare] ( #bool-compare ) | ✅ | ✅ |
74
- | [ compares] ( #compares ) | ✅ | ✅ |
75
- | [ empty] ( #empty ) | ✅ | ✅ |
76
- | [ error-is-as] ( #error-is-as ) | ✅ | ✅ |
77
- | [ error-nil] ( #error-nil ) | ✅ | ✅ |
78
- | [ expected-actual] ( #expected-actual ) | ✅ | ✅ |
79
- | [ float-compare] ( #float-compare ) | ✅ | ❌ |
80
- | [ go-require] ( #go-require ) | ✅ | ❌ |
81
- | [ len] ( #len ) | ✅ | ✅ |
82
- | [ nil-compare] ( #nil-compare ) | ✅ | ✅ |
83
- | [ require-error] ( #require-error ) | ✅ | ❌ |
84
- | [ suite-dont-use-pkg] ( #suite-dont-use-pkg ) | ✅ | ✅ |
85
- | [ suite-extra-assert-call] ( #suite-extra-assert-call ) | ✅ | ✅ |
86
- | [ suite-thelper] ( #suite-thelper ) | ❌ | ✅ |
87
- | [ useless-assert] ( #useless-assert ) | ✅ | ❌ |
72
+ | [ blank-import] ( #blank-import ) | ✅ | ❌ |
73
+ | [ bool-compare] ( #bool-compare ) | ✅ | ✅ |
74
+ | [ compares] ( #compares ) | ✅ | ✅ |
75
+ | [ empty] ( #empty ) | ✅ | ✅ |
76
+ | [ error-is-as] ( #error-is-as ) | ✅ | ✅ |
77
+ | [ error-nil] ( #error-nil ) | ✅ | ✅ |
78
+ | [ error-nil] ( #error-nil ) | ✅ | ✅ |
79
+ | [ expected-actual] ( #expected-actual ) | ✅ | ✅ |
80
+ | [ float-compare] ( #float-compare ) | ✅ | ❌ |
81
+ | [ go-require] ( #go-require ) | ✅ | ❌ |
82
+ | [ len] ( #len ) | ✅ | ✅ |
83
+ | [ negative-positive] ( #negative-positive ) | ✅ | ✅ |
84
+ | [ nil-compare] ( #nil-compare ) | ✅ | ✅ |
85
+ | [ require-error] ( #require-error ) | ✅ | ❌ |
86
+ | [ suite-dont-use-pkg] ( #suite-dont-use-pkg ) | ✅ | ✅ |
87
+ | [ suite-extra-assert-call] ( #suite-extra-assert-call ) | ✅ | ✅ |
88
+ | [ suite-thelper] ( #suite-thelper ) | ❌ | ✅ |
89
+ | [ useless-assert] ( #useless-assert ) | ✅ | ❌ |
88
90
89
91
> ⚠️ Also look at open for contribution [ checkers] ( CONTRIBUTING.md#open-for-contribution )
90
92
@@ -124,7 +126,7 @@ import (
124
126
assert.EqualValues (t, false , result)
125
127
assert.Exactly (t, false , result)
126
128
assert.NotEqual (t, true , result)
127
- assert.NotEqualValues (t, true , result)
129
+ assert.NotEqualValues (t, true , result)
128
130
assert.False (t, !result)
129
131
assert.True (t, result == true )
130
132
// And other variations...
@@ -229,7 +231,7 @@ To turn off this behavior use the `--bool-compare.ignore-custom-types` flag.
229
231
** Reason** : In the first two cases, a common mistake that leads to hiding the incorrect wrapping of sentinel errors.
230
232
In the rest cases – more appropriate ` testify ` API with clearer failure message.
231
233
232
- Also ` error-is-as ` repeats ` go vet ` 's [ errorsas check] ( https://cs.opensource.google/go/x/tools/+/master:go/analysis/passes/errorsas/errorsas.go )
234
+ Also ` error-is-as ` repeats ` go vet ` 's [ errorsas check] ( https://cs.opensource.google/go/x/tools/+/master:go/analysis/passes/errorsas/errorsas.go )
233
235
logic, but without autofix.
234
236
235
237
---
@@ -305,7 +307,7 @@ It is planned [to change the order of assertion arguments](https://github.com/st
305
307
assert.Exactly (t, 42.42 , result)
306
308
assert.True (t, result == 42.42 )
307
309
assert.False (t, result != 42.42 )
308
-
310
+
309
311
✅ assert.InEpsilon (t, 42.42 , result, 0.0001 ) // Or assert.InDelta
310
312
```
311
313
@@ -323,7 +325,7 @@ This checker is similar to the [floatcompare](https://github.com/golangci/golang
323
325
go func () {
324
326
conn, err = lis.Accept ()
325
327
require.NoError (t, err) ❌
326
-
328
+
327
329
if assert.Error (err) {
328
330
assert.FailNow (t, msg) ❌
329
331
}
@@ -337,7 +339,7 @@ go func() {
337
339
This checker is a radically improved analogue of ` go vet ` 's
338
340
[ testinggoroutine] ( https://cs.opensource.google/go/x/tools/+/master:go/analysis/passes/testinggoroutine/doc.go ) check.
339
341
340
- The point of the check is that, according to the [ documentation] ( https://pkg.go.dev/testing#T ) ,
342
+ The point of the check is that, according to the [ documentation] ( https://pkg.go.dev/testing#T ) ,
341
343
functions leading to ` t.FailNow ` (essentially to ` runtime.GoExit ` ) must only be used in the goroutine that runs the test.
342
344
Otherwise, they will not work as declared, namely, finish the test function.
343
345
@@ -376,6 +378,33 @@ P.S. Related `testify`'s [thread](https://github.com/stretchr/testify/issues/772
376
378
377
379
---
378
380
381
+ ### negative-positive
382
+
383
+ ``` go
384
+ ❌ assert.Less (t, a, 0 )
385
+ assert.Greater (t, 0 , a)
386
+ assert.True (t, a < 0 )
387
+ assert.True (t, 0 > a)
388
+ assert.False (t, a >= 0 )
389
+ assert.False (t, 0 <= a)
390
+
391
+ assert.Greater (t, a, 0 )
392
+ assert.Less (t, 0 , a)
393
+ assert.True (t, a > 0 )
394
+ assert.True (t, 0 < a)
395
+ assert.False (t, a <= 0 )
396
+ assert.False (t, 0 >= a)
397
+
398
+ ✅ assert.Negative (t, a)
399
+ assert.Positive (t, a)
400
+ ```
401
+
402
+ ** Autofix** : true. <br >
403
+ ** Enabled by default** : true <br >
404
+ ** Reason** : More appropriate ` testify ` API with clearer failure message.
405
+
406
+ ---
407
+
379
408
### nil-compare
380
409
381
410
``` go
@@ -433,7 +462,7 @@ The best option here is to just use `Nil` / `NotNil` (see [details](https://gith
433
462
** Enabled by default** : true. <br >
434
463
** Reason** : Such "ignoring" of errors leads to further panics, making the test harder to debug.
435
464
436
- [ testify/require] ( https://pkg.go.dev/github.com/stretchr/testify@master/require#hdr-Assertions ) allows
465
+ [ testify/require] ( https://pkg.go.dev/github.com/stretchr/testify@master/require#hdr-Assertions ) allows
437
466
to stop test execution when a test fails.
438
467
439
468
By default ` require-error ` only checks the ` *Error* ` assertions, presented above. <br >
@@ -484,7 +513,7 @@ But sometimes, on the contrary, people want consistency with `s.Assert()` and `s
484
513
``` go
485
514
func (s *MySuite ) TestSomething () {
486
515
// ...
487
-
516
+
488
517
❌
489
518
s.Require ().NoError (err)
490
519
s.Equal (42 , value)
0 commit comments