-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[refurb
] Implement math-constant
(FURB152
)
#8727
Conversation
Ok(Fix::unsafe_edits( | ||
Edit::range_replacement(binding, literal.range()), | ||
[edit], | ||
)) |
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.
Why is this an unsafe fix?
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.
Most likely it changes result of calculations. For example, math.pi
is more precise than 3.14
.
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.
I'm unsure if that means we need to mark it as unsafe, I could go either way though. @charliermarsh?
If we do leave it as unsafe, we should explain why in the rule docs.
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.
Hah, this is an interesting case. I guess I'd lean towards unsafe since it could break tests, etc., if you had hard-coded expectations that differed slightly?
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.
I guess but tests written to check floating point math already should include tolerances. Idk I'm struggling to think of a case where this would change runtime behavior in a meaningful way.
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.
Since it's in preview, it may be fine to just use safe and see if we get feedback.
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.
Sweet! Thanks. Just the one question.
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW3201 | 294 | 147 | 147 | 0 | 0 |
FURB152 | 12 | 12 | 0 | 0 | 0 |
refurb
] Implement math-constant
(FURB152
)
Summary
Implements FURB152 that checks for literals that are similar to constants in
math
module, for example:Use instead:
Related to #1348.
Test Plan
Tested with few test cases.