Skip to content

numberMethodRanges

Reports when number method arguments are outside their valid range.

✅ This rule is included in the ts logical and logicalStrict 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 100
  • Number.prototype.toFixed(digits): digits must be between 0 and 100
  • Number.prototype.toPrecision(precision): precision must be between 1 and 100
  • Number.prototype.toString(radix): radix must be between 2 and 36
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);

This rule is not configurable.

If your codebase is a rare one that overrides those native methods, this rule might not be for you.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.