Skip to content

Commit 7cb4540

Browse files
authored
fix #846: time-equal garbled message when time returned from function (#868)
1 parent 72f9108 commit 7cb4540

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

rule/time-equal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ func (l *lintTimeEqual) Visit(node ast.Node) ast.Visitor {
6060
var failure string
6161
switch expr.Op {
6262
case token.EQL:
63-
failure = fmt.Sprintf("use %s.Equal(%s) instead of %q operator", expr.X, expr.Y, expr.Op)
63+
failure = fmt.Sprintf("use %s.Equal(%s) instead of %q operator", gofmt(expr.X), gofmt(expr.Y), expr.Op)
6464
case token.NEQ:
65-
failure = fmt.Sprintf("use !%s.Equal(%s) instead of %q operator", expr.X, expr.Y, expr.Op)
65+
failure = fmt.Sprintf("use !%s.Equal(%s) instead of %q operator", gofmt(expr.X), gofmt(expr.Y), expr.Op)
6666
}
6767

6868
l.onFailure(lint.Failure{

testdata/time-equal.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ func t() bool {
1212

1313
return t != u // MATCH /use !t.Equal(u) instead of "!=" operator/
1414
}
15+
16+
// issue #846
17+
func isNow(t time.Time) bool { return t == time.Now() } // MATCH /use t.Equal(time.Now()) instead of "==" operator/
18+
func isNotNow(t time.Time) bool { return time.Now() != t } // MATCH /use !time.Now().Equal(t) instead of "!=" operator/

0 commit comments

Comments
 (0)