Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.
Config
Not configurable.
Config examples
"radix": true
Schema
null
Code examples:
Requires the inclusion of the radix parameter when calling `parseInt`.
"rules": { "radix": true }
Passes
const x: string = '11';
const dec: number = parseInt(x, 10);
const bin: number = parseInt(x, 2);
const hex: number = parseInt(x, 16);
Fails
const x: string = '11';
const dec: number = parseInt(x);