-
Notifications
You must be signed in to change notification settings - Fork 130
lint: update floatCompare checker #561
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
lint/floatCompare_checker.go
Outdated
return astp.IsBinaryExpr(exprx) || astp.IsBinaryExpr(expry) | ||
} | ||
|
||
func identExpr(x ast.Node, y ast.Node) (ast.Expr, *ast.BinaryExpr, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be better to make it as a floatCompareChecker
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it might be a identExpr(x, y ast.Node)
;D
lint/floatCompare_checker.go
Outdated
@@ -30,20 +34,66 @@ func (c *floatCompareChecker) VisitLocalExpr(expr ast.Expr) { | |||
return | |||
} | |||
if binexpr.Op == token.EQL || binexpr.Op == token.NEQ { | |||
typx, ok := c.ctx.typesInfo.TypeOf(binexpr.X).(*types.Basic) | |||
if ok && typx.Info()&types.IsFloat != 0 { | |||
if c.isFloatExpr(binexpr) && c.isMultiBinaryExpr(binexpr) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylish: expressions can be splitted by lines 😉
func (c *floatCompareChecker) warn(expr *ast.BinaryExpr) { | ||
var op string | ||
op := ">=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So...we do not support <=
, am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1. Fix print 'binaryExpr' as second argument 2. Add detection NaNCheckExpr: 'x != x' and InfCheckExpr: 'x + x == x'. Result: less false-positives.
…com/go-critic/go-critic into ludweeg/update_floatCompare_checker
Result: less false-positives.