Bug: `no-loss-of-precision` false positive
See original GitHub issueEnvironment
Node version: 16.3.1 npm version: 8.1.2 Local ESLint version: 8.12.0 Global ESLint version: none Operating System: Kubuntu 20
What parser are you using?
Default (Espree)
What did you do?
const test = 555.9771118164062
What did you expect to happen?
This value is actually fine from my testing in chrome, brave, firefox and node console. it shouldn’t be marked as an error
What actually happened?
eslint reported a problem with the no-loss-of-precision
rule
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
Issue Analytics
- State:
- Created a year ago
- Comments:24 (19 by maintainers)
Top Results From Across the Web
What are correct values for precision and recall when the ...
For these special cases, we have defined that if the true positives, false positives and false negatives are all 0, the precision, recall...
Read more >How to Calculate Precision, Recall, and F-Measure for ...
In an imbalanced classification problem with two classes, precision is calculated as the number of true positives divided by the total number of ......
Read more >What's WRONG with Metrics? - Towards Data Science
The main difference between these two types of metrics is that precision denominator contains the False Positives while false positive rate denominator ...
Read more >Precision Recall Method - Outcome for your ML Model - Turing
So this problem is called a False Positive (FP) in the recall and precision classification method. Sometimes, it also gets notified as a...
Read more >Accuracy, Precision, Recall & F1-Score - Python Examples
The precision score can be used in the scenario where the machine learning model is required to identify all positive examples without any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, then let’s just remove “immediately” from the docs.
Please excuse my naivete in posting this without digging deeper into understanding precision in JS beyond reading the rule description and making assumptions. My “testing” was just to the simple extent of setting the value and making sure it was “preserved” in usage in dev consoles like below
To me this showed an example in direct opposition to the part of the rule that states “number literals that immediately lose precision at runtime when converted to a JS Number”. I didn’t know about the
toPrecision
function or that that’s how the rule is handled under the surface. I did a little more testing (see below) and this number definitely has issues with precision at such a small scale. However I don’t think it’s correct to say it “immediately loses precision” as the value does seem to be preserved until you manipulate it in some way… This issue may just be a matter of updating the documentation to better match the behavior under the hood. Also possibly worth adding a link to some documentation discussing how JS handles precision and/or directly to thetoPrecision
MDN page so others who see this error and go to ESLint to check it can become more informed.