Skip to content

useParseIntRadix

Enforce the consistent use of the radix argument when using parseInt().

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");
code-block.js:1:1 lint/nursery/useParseIntRadix  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing radix parameter

> 1 │ parseInt(“071”);
^^^^^^^^^^^^^^^
2 │

Add a non-fractional number between 2 and 36

Unsafe fix: Add a radix of 10

1 │ parseInt(“071”,·10);
++++
parseInt(someValue);
code-block.js:1:1 lint/nursery/useParseIntRadix  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Missing radix parameter

> 1 │ parseInt(someValue);
^^^^^^^^^^^^^^^^^^^
2 │

Add a non-fractional number between 2 and 36

Unsafe fix: Add a radix of 10

1 │ parseInt(someValue,·10);
++++
parseInt("071", "abc");
code-block.js:1:1 lint/nursery/useParseIntRadix ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Invalid radix parameter

> 1 │ parseInt(“071”, “abc”);
^^^^^^^^^^^^^^^^^^^^^^
2 │

Radix must be a non-fractional number between 2 and 36

parseInt("071", 37);
code-block.js:1:1 lint/nursery/useParseIntRadix ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Invalid radix parameter

> 1 │ parseInt(“071”, 37);
^^^^^^^^^^^^^^^^^^^
2 │

Radix must be a non-fractional number between 2 and 36

parseInt();
code-block.js:1:1 lint/nursery/useParseIntRadix ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This call to parseInt has no arguments, it will always return NaN

> 1 │ parseInt();
^^^^^^^^^^
2 │

Add arguments to this function call

parseInt("071", 10);
parseInt("071", 8);
parseFloat(someValue);
biome.json
{
"linter": {
"rules": {
"nursery": {
"useParseIntRadix": "error"
}
}
}
}