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
const binary: string
binary
= (255).
Number.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings. This value is only used for numbers.

toString
(1);
const
const hex: string
hex
= (255).
Number.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings. This value is only used for numbers.

toString
(37);
const
const fixed: string
fixed
= (3.14159).
Number.toFixed(fractionDigits?: number): string

Returns a string representing a number in fixed-point notation.

@paramfractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.

toFixed
(101);
const
const exponential: string
exponential
= (12345).
Number.toExponential(fractionDigits?: number): string

Returns a string containing a number represented in exponential notation.

@paramfractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.

toExponential
(-1);
const
const precision: string
precision
= (12345).
Number.toPrecision(precision?: number): string

Returns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.

@paramprecision Number of significant digits. Must be in the range 1 - 21, inclusive.

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 ❤️‍🔥 around the world by the Flint team and contributors.