[refurb] Implement math-constant (FURB152)#8727
[refurb] Implement math-constant (FURB152)#8727charliermarsh merged 4 commits intoastral-sh:mainfrom
refurb] Implement math-constant (FURB152)#8727Conversation
| Ok(Fix::unsafe_edits( | ||
| Edit::range_replacement(binding, literal.range()), | ||
| [edit], | ||
| )) |
There was a problem hiding this comment.
Most likely it changes result of calculations. For example, math.pi is more precise than 3.14.
There was a problem hiding this comment.
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.
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.
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.
Since it's in preview, it may be fine to just use safe and see if we get feedback.
zanieb
left a comment
There was a problem hiding this comment.
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
mathmodule, for example:Use instead:
Related to #1348.
Test Plan
Tested with few test cases.