Skip to content

useNumberNamespace (since v1.5.0)

Diagnostic Category: lint/style/useNumberNamespace

Sources:

Use the Number properties instead of global ones.

ES2015 moved some globals into the Number properties for consistency.

The rule doesn’t report the globals isFinite and isNan because they have a slightly different behavior to their corresponding Number’s properties Number.isFinite and Number.isNan. You can use the dedicated rules noGlobalIsFinite and noGlobalIsNan to enforce the use of Number.isFinite and Number.isNan.

parseInt("1"); // true
style/useNumberNamespace.js:1:1 lint/style/useNumberNamespace  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Number.parseInt instead of the equivalent global.
  
  > 1 │ parseInt("1"); // true
   ^^^^^^^^
    2 │ 
  
   ES2015 moved some globals into the Number namespace for consistency.
  
   Safe fix: Use Number.parseInt instead.
  
    1  - parseInt("1");·//·true
      1+ Number.parseInt("1");·//·true
    2 2  
  
parseFloat("1.1"); // true
style/useNumberNamespace.js:1:1 lint/style/useNumberNamespace  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Number.parseFloat instead of the equivalent global.
  
  > 1 │ parseFloat("1.1"); // true
   ^^^^^^^^^^
    2 │ 
  
   ES2015 moved some globals into the Number namespace for consistency.
  
   Safe fix: Use Number.parseFloat instead.
  
    1  - parseFloat("1.1");·//·true
      1+ Number.parseFloat("1.1");·//·true
    2 2  
  
NaN; // true
style/useNumberNamespace.js:1:1 lint/style/useNumberNamespace  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Number.NaN instead of the equivalent global.
  
  > 1 │ NaN; // true
   ^^^
    2 │ 
  
   ES2015 moved some globals into the Number namespace for consistency.
  
   Safe fix: Use Number.NaN instead.
  
    1  - NaN;·//·true
      1+ Number.NaN;·//·true
    2 2  
  
Infinity; // true
style/useNumberNamespace.js:1:1 lint/style/useNumberNamespace  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Number.Infinity instead of the equivalent global.
  
  > 1 │ Infinity; // true
   ^^^^^^^^
    2 │ 
  
   ES2015 moved some globals into the Number namespace for consistency.
  
   Safe fix: Use Number.Infinity instead.
  
    1  - Infinity;·//·true
      1+ Number.POSITIVE_INFINITY;·//·true
    2 2  
  
-Infinity; // true
style/useNumberNamespace.js:1:2 lint/style/useNumberNamespace  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Use Number.Infinity instead of the equivalent global.
  
  > 1 │ -Infinity; // true
    ^^^^^^^^
    2 │ 
  
   ES2015 moved some globals into the Number namespace for consistency.
  
   Safe fix: Use Number.Infinity instead.
  
    1  - -Infinity;·//·true
      1+ Number.NEGATIVE_INFINITY;·//·true
    2 2  
  
Number.parseInt("1"); // false
Number.parseFloat("1.1"); // false
Number.NaN; // false
Number.POSITIVE_INFINITY; // false
Number.NEGATIVE_INFINITY; // false