numberMethodRanges
Reports when number method arguments are outside their valid range.
✅ This rule is included in the ts logical presets.
Number methods such as toExponential, toFixed, toPrecision, and toString have specific valid ranges for their arguments.
Passing values outside these ranges will throw a RangeError at runtime.
This rule flags numeric literal arguments that are outside the valid range:
Number.prototype.toExponential(digits): digits must be between 0 and 100Number.prototype.toFixed(digits): digits must be between 0 and 100Number.prototype.toPrecision(precision): precision must be between 1 and 100Number.prototype.toString(radix): radix must be between 2 and 36
Examples
Section titled “Examples”const binary = (255).toString(1);const hex = (255).toString(37);const fixed = (3.14159).toFixed(101);const exponential = (12345).toExponential(-1);const precision = (12345).toPrecision(0);const binary = (255).toString(2);const hex = (255).toString(16);const fixed = (3.14159).toFixed(2);const exponential = (12345).toExponential(5);const precision = (12345).toPrecision(10);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase is a rare one that overrides those native methods, this rule might not be for you.
Further Reading
Section titled “Further Reading”- MDN: Number.prototype.toExponential()
- MDN: Number.prototype.toFixed()
- MDN: Number.prototype.toPrecision()
- MDN: Number.prototype.toString()
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Oxlint:
oxc/number-arg-out-of-range
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.