Skip to content

Commit 5e3158a

Browse files
committed
always wrap in () when its negative
1 parent 96219fa commit 5e3158a

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

rules/prefer-bigint-literals.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,7 @@ const create = context => {
125125
const tokenBefore = context.sourceCode.getTokenBefore(nodeToReplace);
126126

127127
if (text.startsWith('-') && !text.startsWith('-(')) {
128-
const needsParentheses
129-
// BigInt(-1).toString() -> (-1n).toString()
130-
= (parent.type === 'MemberExpression' && parent.object === callExpression)
131-
// 2n -BigInt("-1") -> 2n -(-1n)
132-
|| (tokenBefore?.type === 'Punctuator' && (tokenBefore.value === '-' || tokenBefore.value === '+'));
133-
134-
if (needsParentheses) {
135-
text = `(${text})`;
136-
}
128+
text = `(${text})`;
137129
}
138130

139131
if (tokenBefore && needsSemicolon(tokenBefore, context, text)) {

test/snapshots/prefer-bigint-literals.js.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Generated by [AVA](https://avajs.dev).
419419
| ^^^^^^^^^^^^ Prefer using bigint literal over \`BigInt(…)\`.␊
420420
421421
Output:␊
422-
1 | -1n␊
422+
1 | (-1n)
423423
`
424424

425425
## invalid(23): BigInt("+1")
@@ -457,7 +457,7 @@ Generated by [AVA](https://avajs.dev).
457457
| ^^^^^^^^^^ Prefer using bigint literal over \`BigInt(…)\`.␊
458458
459459
Output:␊
460-
1 | -1n␊
460+
1 | (-1n)
461461
`
462462

463463
## invalid(25): BigInt(+1)
@@ -617,7 +617,7 @@ Generated by [AVA](https://avajs.dev).
617617
Output:␊
618618
1 |␊
619619
2 | foo␊
620-
3 | ;-1n␊
620+
3 | ;(-1n)
621621
4 | ␊
622622
`
623623

11 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)