Skip to content

Commit d7e3d5e

Browse files
authored
fix: time-naming issue #571 (#572)
resolves #571
1 parent 9b85893 commit d7e3d5e

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

rule/time-naming.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ func (w *lintTimeNames) Visit(node ast.Node) ast.Visitor {
7676
// timeSuffixes is a list of name suffixes that imply a time unit.
7777
// This is not an exhaustive list.
7878
var timeSuffixes = []string{
79-
"Sec", "Secs", "Seconds",
79+
"Hour", "Hours",
80+
"Min", "Mins", "Minutes", "Minute",
81+
"Sec", "Secs", "Seconds", "Second",
8082
"Msec", "Msecs",
81-
"Milli", "Millis", "Milliseconds",
82-
"Usec", "Usecs", "Microseconds",
83+
"Milli", "Millis", "Milliseconds", "Millisecond",
84+
"Usec", "Usecs", "Microseconds", "Microsecond",
8385
"MS", "Ms",
8486
}
8587

test/time-naming_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/mgechev/revive/rule"
7+
)
8+
9+
// TestTimeNamingRule rule.
10+
func TestTimeNaming(t *testing.T) {
11+
testRule(t, "time-naming", &rule.TimeNamingRule{})
12+
}

testdata/time-naming.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package testdata
2+
3+
import "time"
4+
5+
var (
6+
Hour = time.Hour // MATCH /var Hour is of type time.Duration; don't use unit-specific suffix "Hour"/
7+
oneHour = time.Hour // MATCH /var oneHour is of type time.Duration; don't use unit-specific suffix "Hour"/
8+
twoHours = 2 * time.Hour // MATCH /var twoHours is of type time.Duration; don't use unit-specific suffix "Hours"/
9+
TenHours = 10 * time.Hour // MATCH /var TenHours is of type time.Duration; don't use unit-specific suffix "Hours"/
10+
SixHours = 6 * time.Hour // MATCH /var SixHours is of type time.Duration; don't use unit-specific suffix "Hours"/
11+
12+
oneMin = time.Minute // MATCH /var oneMin is of type time.Duration; don't use unit-specific suffix "Min"/
13+
Min = time.Minute // MATCH /var Min is of type time.Duration; don't use unit-specific suffix "Min"/
14+
twoMin = 2 * time.Minute // MATCH /var twoMin is of type time.Duration; don't use unit-specific suffix "Min"/
15+
SixMin = 6 * time.Minute // MATCH /var SixMin is of type time.Duration; don't use unit-specific suffix "Min"/
16+
SixMins = 6 * time.Minute // MATCH /var SixMins is of type time.Duration; don't use unit-specific suffix "Mins"/
17+
SixMinutes = 6 * time.Minute // MATCH /var SixMinutes is of type time.Duration; don't use unit-specific suffix "Minutes"/
18+
19+
oneSec = time.Second // MATCH /var oneSec is of type time.Duration; don't use unit-specific suffix "Sec"/
20+
Sec = time.Second // MATCH /var Sec is of type time.Duration; don't use unit-specific suffix "Sec"/
21+
SixSec = 6 * time.Second // MATCH /var SixSec is of type time.Duration; don't use unit-specific suffix "Sec"/
22+
twoSecs = 2 * time.Second // MATCH /var twoSecs is of type time.Duration; don't use unit-specific suffix "Secs"/
23+
SixSeconds = 6 * time.Second // MATCH /var SixSeconds is of type time.Duration; don't use unit-specific suffix "Seconds"/
24+
oneSecond = time.Second // MATCH /var oneSecond is of type time.Duration; don't use unit-specific suffix "Second"/
25+
Second = time.Second // MATCH /var Second is of type time.Duration; don't use unit-specific suffix "Second"/
26+
27+
SixMsec = 6 * time.Millisecond // MATCH /var SixMsec is of type time.Duration; don't use unit-specific suffix "Msec"/
28+
oneMsec = time.Millisecond // MATCH /var oneMsec is of type time.Duration; don't use unit-specific suffix "Msec"/
29+
SixMsecs = 6 * time.Millisecond // MATCH /var SixMsecs is of type time.Duration; don't use unit-specific suffix "Msecs"/
30+
oneMilli = time.Millisecond // MATCH /var oneMilli is of type time.Duration; don't use unit-specific suffix "Milli"/
31+
SixMillis = 6 * time.Millisecond // MATCH /var SixMillis is of type time.Duration; don't use unit-specific suffix "Millis"/
32+
SixMilliseconds = 6 * time.Millisecond // MATCH /var SixMilliseconds is of type time.Duration; don't use unit-specific suffix "Milliseconds"/
33+
oneMillisecond = time.Millisecond // MATCH /var oneMillisecond is of type time.Duration; don't use unit-specific suffix "Millisecond"/
34+
Millisecond = time.Millisecond // MATCH /var Millisecond is of type time.Duration; don't use unit-specific suffix "Millisecond"/
35+
36+
oneUsec = 1 * time.Microsecond // MATCH /var oneUsec is of type time.Duration; don't use unit-specific suffix "Usec"/
37+
twoUsec = 2 * time.Microsecond // MATCH /var twoUsec is of type time.Duration; don't use unit-specific suffix "Usec"/
38+
SixUsec = 6 * time.Microsecond // MATCH /var SixUsec is of type time.Duration; don't use unit-specific suffix "Usec"/
39+
SixUsecs = 6 * time.Microsecond // MATCH /var SixUsecs is of type time.Duration; don't use unit-specific suffix "Usecs"/
40+
twoMicroseconds = 2 * time.Microsecond // MATCH /var twoMicroseconds is of type time.Duration; don't use unit-specific suffix "Microseconds"/
41+
SixMicroseconds = 6 * time.Microsecond // MATCH /var SixMicroseconds is of type time.Duration; don't use unit-specific suffix "Microseconds"/
42+
oneMicrosecond = 1 * time.Microsecond // MATCH /var oneMicrosecond is of type time.Duration; don't use unit-specific suffix "Microsecond"/
43+
SixMS = 6 * time.Microsecond // MATCH /var SixMS is of type time.Duration; don't use unit-specific suffix "MS"/
44+
oneMS = 1 * time.Microsecond // MATCH /var oneMS is of type time.Duration; don't use unit-specific suffix "MS"/
45+
46+
)

0 commit comments

Comments
 (0)