useBigintLiterals (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useBigintLiterals - This rule has a safe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
unicorn/prefer-bigint-literals
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useBigintLiterals": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.