Lint Rules

useNumericLiterals (since v11.0.0)

Disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals

Examples

Invalid

parseInt("111110111", 2) === 503;
nursery/useNumericLiterals.js:1:1 lint/nursery/useNumericLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━

   Use binary literals instead of parseInt()
  
  > 1 │ parseInt("111110111", 2) === 503;
   ^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Replace with binary literals
  
    1  - parseInt("111110111",·2)·===·503;
      1+ 0b111110111·===·503;
    2 2  
  
Number.parseInt("767", 8) === 503;
nursery/useNumericLiterals.js:1:1 lint/nursery/useNumericLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━

   Use octal literals instead of Number.parseInt()
  
  > 1 │ Number.parseInt("767", 8) === 503;
   ^^^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Replace with octal literals
  
    1  - Number.parseInt("767",·8)·===·503;
      1+ 0o767·===·503;
    2 2  
  

Valid

parseInt(1);
parseInt(1, 3);
Number.parseInt(1);
Number.parseInt(1, 3);

0b111110111 === 503;
0o767 === 503;
0x1F7 === 503;

a[parseInt](1,2);

parseInt(foo);
parseInt(foo, 2);
Number.parseInt(foo);
Number.parseInt(foo, 2);