Skip to content

useBigintLiterals (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useBigintLiterals": "error"
}
}
}
}

Enforce the use of bigint literals over the BigInt() constructor.

A bigint literal with the n suffix is more concise than calling BigInt() with a number or string literal, and it is evaluated at parse time rather than converted at runtime.

The rule only reports calls whose argument is a number or string literal that can be expressed as a bigint literal. Calls with a computed argument are ignored.

const bigint = BigInt(1);
code-block.js:1:16 lint/nursery/useBigintLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This BigInt() call can be replaced with a bigint literal.

> 1 │ const bigint = BigInt(1);
│ ^^^^^^^^^
2 │

ℹ A bigint literal with the n suffix is more concise, and it is evaluated at parse time instead of being converted at runtime.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Replace with a bigint literal.

1 │ - const·bigint·=·BigInt(1);
1 │ + const·bigint·=·1n;
2 2 │

const large = BigInt("9007199254740993");
code-block.js:1:15 lint/nursery/useBigintLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This BigInt() call can be replaced with a bigint literal.

> 1 │ const large = BigInt("9007199254740993");
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ A bigint literal with the n suffix is more concise, and it is evaluated at parse time instead of being converted at runtime.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Replace with a bigint literal.

1 │ - const·large·=·BigInt("9007199254740993");
1 │ + const·large·=·9007199254740993n;
2 2 │

const hex = BigInt("0xFF");
code-block.js:1:13 lint/nursery/useBigintLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This BigInt() call can be replaced with a bigint literal.

> 1 │ const hex = BigInt("0xFF");
│ ^^^^^^^^^^^^^^
2 │

ℹ A bigint literal with the n suffix is more concise, and it is evaluated at parse time instead of being converted at runtime.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Replace with a bigint literal.

1 │ - const·hex·=·BigInt("0xFF");
1 │ + const·hex·=·0xFFn;
2 2 │

const negative = BigInt(-1);
code-block.js:1:18 lint/nursery/useBigintLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This BigInt() call can be replaced with a bigint literal.

> 1 │ const negative = BigInt(-1);
│ ^^^^^^^^^^
2 │

ℹ A bigint literal with the n suffix is more concise, and it is evaluated at parse time instead of being converted at runtime.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Safe fix: Replace with a bigint literal.

1 │ - const·negative·=·BigInt(-1);
1 │ + const·negative·=·-1n;
2 2 │

const bigint = 1n;
const large = 9007199254740993n;
const hex = 0xFFn;
const computed = BigInt(getSomeNumber());
const fraction = BigInt(1.5);