Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time-equal garbled message when time returned from function #846

Closed
mdelah opened this issue Jul 3, 2023 · 1 comment · Fixed by #868
Closed

time-equal garbled message when time returned from function #846

mdelah opened this issue Jul 3, 2023 · 1 comment · Fixed by #868

Comments

@mdelah
Copy link
Contributor

mdelah commented Jul 3, 2023

Describe the bug
The time-equal rule passes an ast.Expr to a %s placeholder in its message format, but not all ast.Expr implement String(), so junk is output for certain kinds of expressions (such as comparing a time.Time that's returned from a function call).

To Reproduce
Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. I run it with the following flags & configuration file:
revive -config revive.toml time-equal-test.go
# config file
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.0
errorCode = 0
warningCode = 0

[rule.time-equal]

Source file time-equal-test.go:

package test

import "time"

func isNow(t time.Time) bool { return t == time.Now() }

Expected behavior
Something more readable than:

time-equal-test.go:5:39: use t.Equal(&{%!s(*ast.SelectorExpr=&{0xc00007e7a0 0xc00007e7c0}) %!s(token.Pos=81) [] %!s(token.Pos=0) %!s(token.Pos=82)}) instead of "==" operator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants