Skip to content

Conversation

@baevm
Copy link
Contributor

@baevm baevm commented Oct 21, 2025

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

image
@github-actions github-actions bot changed the title fix (prefer-bigint-literals): fix add support for numbers/strings with operators fix (prefer-bigint-literals): fix add support for numbers/strings with operators Oct 21, 2025
@fisker
Copy link
Collaborator

fisker commented Oct 23, 2025

I opened #2733, because I think there are maybe people writes BigInt("-1"), but I don't think anyone would write BigInt(!1), it should be a mistake.

@fisker fisker closed this Oct 23, 2025
@fisker
Copy link
Collaborator

fisker commented Oct 23, 2025

I didn't notice, this is a PR, not an issue. Sorry!

@fisker fisker reopened this Oct 23, 2025

// BigInt("+1") -> 1n
if (raw[0] === '+') {
raw = raw.slice(1);
Copy link
Collaborator

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")?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And BigInt("+ 1")

Copy link
Collaborator

@fisker fisker Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BigInt(" -1 ") 
BigInt(" +1 ") 
Copy link
Contributor Author

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

@fisker
Copy link
Collaborator

fisker commented Oct 23, 2025

Need test -BigInt(-1) and -BigInt("-1"), I think they will fail.

@fisker
Copy link
Collaborator

fisker commented Oct 23, 2025

There can also ASI issue since the fixed code inserts -.

foo // <-- no semicolon here BigInt("-1") 
}

// BigInt("+1") -> 1n
if (raw[0] === '+') {
Copy link
Collaborator

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

Copy link
Contributor Author

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 ")

@baevm
Copy link
Contributor Author

baevm commented Oct 27, 2025

Need test -BigInt(-1) and -BigInt("-1"), I think they will fail.

fixed, added tests

There can also ASI issue since the fixed code inserts -.

foo // <-- no semicolon here BigInt("-1") 

not sure about this, but i think it is working fine? added test for this

Comment on lines +647 to +648
2 | foo␊
3 | -1n␊
Copy link
Collaborator

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 
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Copy link
Collaborator

@fisker fisker Oct 27, 2025

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␊
Copy link
Collaborator

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)

@fisker
Copy link
Collaborator

fisker commented Oct 27, 2025

Another test 2n - BigInt("-1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants