@@ -14,25 +14,23 @@ Install dev tools...
14
14
### 2) Create a checker skeleton in ` internal/checkers/{checker_name}.go `
15
15
16
16
For example, we want to create a new checker
17
- ` Zero ` in ` internal/checkers/zero .go ` :
17
+ ` TimeCompare ` in ` internal/checkers/time_compare .go ` :
18
18
19
19
``` go
20
20
package checkers
21
21
22
- // Zero detects situations like
22
+ // TimeCompare detects situations like
23
23
//
24
- // assert.Equal(t, 0, count)
25
- // assert.Equal(t, nil, userObj)
24
+ // assert.Equal(t, expTs, actualTs)
26
25
//
27
26
// and requires
28
27
//
29
- // assert.Zero(t, count)
30
- // assert.Zero(t, userObj)
31
- type Zero struct {}
28
+ // assert.True(t, actualTs.Equal(expTs))
29
+ type TimeCompare struct {}
32
30
33
- // NewZero constructs Zero checker.
34
- func NewZero () Zero { return Zero {} }
35
- func (Zero ) Name () string { return " zero " }
31
+ // NewTimeCompare constructs TimeCompare checker.
32
+ func NewTimeCompare () TimeCompare { return TimeCompare {} }
33
+ func (TimeCompare ) Name () string { return " TimeCompare " }
36
34
```
37
35
38
36
The above code is enough to satisfy the ` checkers.Checker ` interface.
@@ -41,14 +39,14 @@ The above code is enough to satisfy the `checkers.Checker` interface.
41
39
42
40
The earlier the checker is in [ the registry] ( internal/checkers/checkers_registry.go ) , the more priority it is.
43
41
44
- For example, the ` zero ` checker takes precedence over the ` expected-actual ` or ` empty ` ,
45
- because its check is more "narrow" and when you fix the warning from ` zero ` ,
42
+ For example, the ` TimeCompare ` checker takes precedence over the ` empty ` and ` expected-actual ` ,
43
+ because its check is more "narrow" and when you fix the warning from ` TimeCompare ` ,
46
44
the rest of the checkers will become irrelevant.
47
45
48
46
``` go
49
47
var registry = checkersRegistry{
50
48
// ...
51
- {factory: asCheckerFactory (NewZero ), enabledByDefault: false },
49
+ {factory: asCheckerFactory (NewTimeCompare ), enabledByDefault: false },
52
50
// ...
53
51
{factory: asCheckerFactory (NewEmpty), enabledByDefault: true },
54
52
// ...
@@ -61,7 +59,7 @@ By default, we disable the checker if we doubt its 100% usefulness.
61
59
62
60
### 4) Create new tests generator in ` internal/testgen/gen_{checker_name}.go `
63
61
64
- Create new ` ZeroTestsGenerator ` in ` internal/testgen/gen_zero .go ` .
62
+ Create new ` TimeCompareTestsGenerator ` in ` internal/testgen/gen_time_compare .go ` .
65
63
66
64
See examples in adjacent files.
67
65
89
87
90
88
### 7) Implement the checker
91
89
92
- ` Zero ` is an example of [ checkers.RegularChecker] ( ./internal/checkers/checker.go ) because it works with "general"
90
+ ` TimeCompare ` is an example of [ checkers.RegularChecker] ( ./internal/checkers/checker.go ) because it works with "general"
93
91
assertion call. For more complex checkers, use the [ checkers.AdvancedChecker] ( ./internal/checkers/checker.go ) interface.
94
92
95
93
If the checker turns out to be too “fat”, then you can omit some obviously rare combinations,
@@ -140,7 +138,6 @@ Describe a new checker in [checkers section](./README.md#checkers).
140
138
- [ suite-run] ( #suite-run )
141
139
- [ suite-test-name] ( #suite-test-name )
142
140
- [ useless-assert] ( #useless-assert )
143
- - [ zero] ( #zero )
144
141
145
142
---
146
143
@@ -409,38 +406,5 @@ assert.ErrorContains(t, err, "user") ❌
409
406
410
407
---
411
408
412
- ### zero
413
-
414
- ```go
415
- ❌ assert.Equal(t, 0, count)
416
- assert.Equal(t, nil, userObj)
417
- assert.Equal(t, "", name)
418
- // etc.
419
-
420
- ✅ assert.Zero(t, count)
421
- assert.Zero(t, userObj)
422
- assert.Zero(t, name)
423
- ```
424
-
425
- **Autofix**: true. <br>
426
- **Enabled by default**: false. <br>
427
- **Reason**: Just for your reflection and suggestion. <br>
428
- **Related issues**: [#75](https:// github.com/Antonboom/testifylint/issues/75)
429
-
430
- I'm not sure if anyone uses `assert.Zero` – it looks strange and conflicts with `assert.Empty`:
431
-
432
- ```go
433
- ❌ assert.Equal(t, "", result)
434
- assert.Nil(t, errCh)
435
-
436
- ✅ assert.Empty(t, result)
437
- assert.Empty(t, errCh)
438
- ```
439
-
440
- Maybe it's better to make configurable support for other types in the `empty` checker and
441
- vice versa to prohibit the `Zero`?
442
-
443
- ---
444
-
445
409
Any other figments of your imagination are welcome 🙏<br>
446
410
List of `testify` functions [here](https:// pkg.go.dev/github.com/stretchr/testify@master/assert#pkg-functions).
0 commit comments