New rule proposal: disallow === -0
See original GitHub issuePlease describe what the rule should do:
The rule should warn against code that tries to use the ===
operator to compare against -0
, since that will not work as intended. That is, code like x === -0
will pass for both +0
and -0
. The author probably intended Object.is(x, -0)
.
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [x] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
// Don't accept negative zero
if (x === -0) {
throw new TypeError("-0 is not a valid value for this API");
}
// This code intends to only throw on -0, but instead throws on +0 as well.
// Allow any negative number, including negative zero
if (x === -0 || x < 0) {
// use x
}
// This code intends to disallow +0, but instead allows it through.
Why should this rule be included in ESLint (instead of a plugin)?
This rule seems like a fairly universal potential mistake. It meets all the core rule guidelines and is a perfect candidate for linting.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:16 (12 by maintainers)
Top Results From Across the Web
5 RMD Changes Looming With Passage Of SECURE 2.0 Act
The new rules would allow someone to treat this all as one distribution for purposes of RMD accounts.
Read more >Federal Register/Vol. 87, No. 46/Wednesday, March 9, 2022 ...
ACTION: Proposed rule. SUMMARY: The Securities and Exchange. Commission is proposing new rules under the Investment Advisers Act of.
Read more >Proposed rule: Private Fund Advisers - SEC.gov
In addition, we are proposing rules that would prohibit all private fund advisers, including those that are not registered with the Commission, ...
Read more >US Department of Labor announces proposed rule on ...
US Department of Labor announces proposed rule on classifying employees, independent contractors; seeks to return to longstanding interpretation.
Read more >Congress considers retirement rule changes, including catch ...
One would allow employers to automatically enroll their workers in emergency savings accounts, at 3% of pay, that could be accessed at least ......
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 FreeTop 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
Top GitHub Comments
Sounds great, thanks! I’ll most likely work on this over the upcoming weekend.
I can see an argument for this as a core rule, as it’s one of those language quirks that you could spend days trying to debug if you misunderstood what happens, and I agree with the comparison to use-isnan, as that rule solves a similar problem.
I’d even go so far as to say I think it should be included in “eslint:recommended”.
I’ll champion.
@domenic are you willing to submit a PR for this rule if the team accepts it?