-
-
Notifications
You must be signed in to change notification settings - Fork 426
prefer-bigint-literals: Support signed numbers and strings
#2784
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
base: main
Are you sure you want to change the base?
Conversation
prefer-bigint-literals): fix add support for numbers/strings with operators
|
I opened #2733, because I think there are maybe people writes |
|
I didn't notice, this is a PR, not an issue. Sorry! |
rules/prefer-bigint-literals.js
Outdated
|
|
||
| // BigInt("+1") -> 1n | ||
| if (raw[0] === '+') { | ||
| raw = raw.slice(1); |
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.
Can you add test for BigInt("++1")?
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 BigInt("+ 1")
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.
BigInt(" -1 ")
BigInt(" +1 ")
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.
added tests:
BigInt("++1") - valid
BigInt("+ 1") - valid
BigInt(" -1 ") - invalid
BigInt(" +1 ") - invalid with suggestion
|
Need test |
|
There can also ASI issue since the fixed code inserts |
fixed, added tests
not sure about this, but i think it is working fine? added test for this |
|
Another test |
|
Bump :) |
59c1ea2 to
1bd819c
Compare
1bd819c to
b8460db
Compare
|
Sorry, I mean |
|
I'm taking a final look. |
|
I pushed some simplification, can you take a look? |
| 'BigInt(1) + BigInt(2)', | ||
| 'BigInt(1) ** 2n', | ||
| 'condition ? BigInt(1) : BigInt(2)', | ||
| '+BigInt(1)', |
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.
Same runtime error, this is not what we should care.
+BigInt(1)
VM782:1 Uncaught TypeError: Cannot convert a BigInt value to a number
at <anonymous>:1:1
(anonymous) @ VM782:1
+1n
VM792:1 Uncaught TypeError: Cannot convert a BigInt value to a number
at <anonymous>:1:1
prefer-bigint-literals): fix add support for numbers/strings with operatorsprefer-bigint-literals: Support signed numbers and strings

Fixes #2733, added support for
BigInt('+1'),BigInt('-1'),BigInt(+1),BigInt(-1). Not sure aboutBigInt(!1)andBigInt(~1), looks like those also valid?