From 7cb4540a46f19f7da7a1cb9cf6ab661aec3e0d06 Mon Sep 17 00:00:00 2001 From: chavacava Date: Sat, 12 Aug 2023 09:05:46 +0200 Subject: [PATCH] fix #846: time-equal garbled message when time returned from function (#868) --- rule/time-equal.go | 4 ++-- testdata/time-equal.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rule/time-equal.go b/rule/time-equal.go index 72ecf26..3b85e18 100644 --- a/rule/time-equal.go +++ b/rule/time-equal.go @@ -60,9 +60,9 @@ func (l *lintTimeEqual) Visit(node ast.Node) ast.Visitor { var failure string switch expr.Op { case token.EQL: - failure = fmt.Sprintf("use %s.Equal(%s) instead of %q operator", expr.X, expr.Y, expr.Op) + failure = fmt.Sprintf("use %s.Equal(%s) instead of %q operator", gofmt(expr.X), gofmt(expr.Y), expr.Op) case token.NEQ: - failure = fmt.Sprintf("use !%s.Equal(%s) instead of %q operator", expr.X, expr.Y, expr.Op) + failure = fmt.Sprintf("use !%s.Equal(%s) instead of %q operator", gofmt(expr.X), gofmt(expr.Y), expr.Op) } l.onFailure(lint.Failure{ diff --git a/testdata/time-equal.go b/testdata/time-equal.go index be72c4e..f31a05a 100644 --- a/testdata/time-equal.go +++ b/testdata/time-equal.go @@ -12,3 +12,7 @@ func t() bool { return t != u // MATCH /use !t.Equal(u) instead of "!=" operator/ } + +// issue #846 +func isNow(t time.Time) bool { return t == time.Now() } // MATCH /use t.Equal(time.Now()) instead of "==" operator/ +func isNotNow(t time.Time) bool { return time.Now() != t } // MATCH /use !time.Now().Equal(t) instead of "!=" operator/