-
-
Notifications
You must be signed in to change notification settings - Fork 418
fix (prefer-bigint-literals): fix add support for numbers/strings with operators
#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 |
rules/prefer-bigint-literals.js
Outdated
| } | ||
|
|
||
| // BigInt("+1") -> 1n | ||
| if (raw[0] === '+') { |
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.
Unlike "-1", "+1" probably a mistake, let's use suggestion instead of autofix. Same for UnaryExpression
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.
replaced with suggestion, also fixed logic for cases with spaces BigInt(" +1 ")
fixed, added tests
not sure about this, but i think it is working fine? added test for this |
| 2 | foo␊ | ||
| 3 | -1n␊ |
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.
This should be
foo
;-1n
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.
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.
There is a needsSemicolon utility for it.
| > Output | ||
| `␊ | ||
| 1 | 1n␊ |
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.
Instead of 1n, better fix to -(-1n)
|
Another test |

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