noNumberArgumentOutOfRange (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.6 - Diagnostic Category:
lint/nursery/noNumberArgumentOutOfRange - This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Inspired from
oxc/number-arg-out-of-range
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noNumberArgumentOutOfRange": "error" } } }}Description
Section titled “Description”Disallow number method arguments that are outside the range the method accepts.
Some methods of numbers only accept a limited range of values as their first argument,
and throw a RangeError when called with anything else:
toString()accepts a base (radix) between 2 and 36.toFixed()accepts between 0 and 100 digits after the decimal point.toExponential()accepts between 0 and 100 digits after the decimal point.toPrecision()accepts between 1 and 100 significant digits.
The fractional part of the argument is dropped before the range is checked,
so toString(36.5) is the same as toString(36).
This rule only checks arguments written as number literals.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const binary = value.toString(1);code-block.js:1:31 lint/nursery/noNumberArgumentOutOfRange ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The argument of toString() is out of range.
> 1 │ const binary = value.toString(1);
│ ^
2 │
ℹ toString() throws a RangeError when its first argument is not between 2 and 36.
ℹ Pass a number between 2 and 36.
ℹ 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.
const text = value.toString(64);code-block.js:1:29 lint/nursery/noNumberArgumentOutOfRange ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The argument of toString() is out of range.
> 1 │ const text = value.toString(64);
│ ^^
2 │
ℹ toString() throws a RangeError when its first argument is not between 2 and 36.
ℹ Pass a number between 2 and 36.
ℹ 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.
const price = value.toFixed(-1);code-block.js:1:29 lint/nursery/noNumberArgumentOutOfRange ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The argument of toFixed() is out of range.
> 1 │ const price = value.toFixed(-1);
│ ^^
2 │
ℹ toFixed() throws a RangeError when its first argument is not between 0 and 100.
ℹ Pass a number between 0 and 100.
ℹ 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.
const rounded = value.toPrecision(0);code-block.js:1:35 lint/nursery/noNumberArgumentOutOfRange ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The argument of toPrecision() is out of range.
> 1 │ const rounded = value.toPrecision(0);
│ ^
2 │
ℹ toPrecision() throws a RangeError when its first argument is not between 1 and 100.
ℹ Pass a number between 1 and 100.
ℹ 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.
const hex = value.toString(16);const price = value.toFixed(2);const scientific = value.toExponential(100);const rounded = value.toPrecision(3);const text = value.toString(base);Caveats
Section titled “Caveats”This rule assumes that these methods are called on a number. It doesn’t check the type of the value the method is called on.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.