Skip to content

Commit

Permalink
fix #846: time-equal garbled message when time returned from function (
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava committed Aug 12, 2023
1 parent 72f9108 commit 7cb4540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rule/time-equal.go
Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions testdata/time-equal.go
Expand Up @@ -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/

0 comments on commit 7cb4540

Please sign in to comment.