Skip to content

parseIntRadixes

Reports parseInt calls that are missing or have an invalid radix parameter.

✅ This rule is included in the ts logical presets.

When using the parseInt() function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is. By default, parseInt() will autodetect decimal and hexadecimal (via 0x prefix). Prior to ECMAScript 5, parseInt() also autodetected octal literals, which caused problems because many developers assumed a leading 0 would be ignored.

This confusion led to the suggestion that you always use the radix parameter to parseInt() to eliminate unintended consequences.

parseInt("071");
parseInt(someValue);
Number.parseInt("071");
parseInt("10", 1);
parseInt("10", 37);

This rule is not configurable.

If you are confident that your codebase always uses decimal strings without leading zeros, it may be preferable to disable this rule.

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