Skip to content

Commit 328c08c

Browse files
committed
contribution: remove zero checker
1 parent af4a8c9 commit 328c08c

File tree

1 file changed

+13
-49
lines changed

1 file changed

+13
-49
lines changed

CONTRIBUTING.md

+13-49
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@ Install dev tools...
1414
### 2) Create a checker skeleton in `internal/checkers/{checker_name}.go`
1515

1616
For example, we want to create a new checker
17-
`Zero` in `internal/checkers/zero.go`:
17+
`TimeCompare` in `internal/checkers/time_compare.go`:
1818

1919
```go
2020
package checkers
2121

22-
// Zero detects situations like
22+
// TimeCompare detects situations like
2323
//
24-
// assert.Equal(t, 0, count)
25-
// assert.Equal(t, nil, userObj)
24+
// assert.Equal(t, expTs, actualTs)
2625
//
2726
// and requires
2827
//
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{}
3230

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" }
3634
```
3735

3836
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.
4139

4240
The earlier the checker is in [the registry](internal/checkers/checkers_registry.go), the more priority it is.
4341

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`,
4644
the rest of the checkers will become irrelevant.
4745

4846
```go
4947
var registry = checkersRegistry{
5048
// ...
51-
{factory: asCheckerFactory(NewZero), enabledByDefault: false},
49+
{factory: asCheckerFactory(NewTimeCompare), enabledByDefault: false},
5250
// ...
5351
{factory: asCheckerFactory(NewEmpty), enabledByDefault: true},
5452
// ...
@@ -61,7 +59,7 @@ By default, we disable the checker if we doubt its 100% usefulness.
6159

6260
### 4) Create new tests generator in `internal/testgen/gen_{checker_name}.go`
6361

64-
Create new `ZeroTestsGenerator` in `internal/testgen/gen_zero.go`.
62+
Create new `TimeCompareTestsGenerator` in `internal/testgen/gen_time_compare.go`.
6563

6664
See examples in adjacent files.
6765

@@ -89,7 +87,7 @@ FAIL
8987

9088
### 7) Implement the checker
9189

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"
9391
assertion call. For more complex checkers, use the [checkers.AdvancedChecker](./internal/checkers/checker.go) interface.
9492

9593
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).
140138
- [suite-run](#suite-run)
141139
- [suite-test-name](#suite-test-name)
142140
- [useless-assert](#useless-assert)
143-
- [zero](#zero)
144141

145142
---
146143

@@ -409,38 +406,5 @@ assert.ErrorContains(t, err, "user") ❌
409406

410407
---
411408

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-
445409
Any other figments of your imagination are welcome 🙏<br>
446410
List of `testify` functions [here](https://pkg.go.dev/github.com/stretchr/testify@master/assert#pkg-functions).

0 commit comments

Comments
 (0)