Skip to content

Latest commit

 

History

History
113 lines (82 loc) · 3.51 KB

prefer-number-properties.md

File metadata and controls

113 lines (82 loc) · 3.51 KB

Prefer Number static properties over global ones.

Enforces the use of:

This rule is partly fixable.

Fail

const foo = parseInt('10', 2);
const foo = parseFloat('10.5');
const foo = isNaN(10);
const foo = isFinite(10);
if (Object.is(foo, NaN)) {}
const isPositiveZero = value => value === 0 && 1 / value === Infinity;
const isNegativeZero = value => value === 0 && 1 / value === -Infinity;
const {parseInt} = Number;
const foo = parseInt('10', 2);

Pass

const foo = Number.parseInt('10', 2);
const foo = Number.parseFloat('10.5');
const foo = Number.isNaN(10);
const foo = Number.isFinite(10);
if (Object.is(foo, Number.NaN)) {}
const isPositiveZero = value => value === 0 && 1 / value === Number.POSITIVE_INFINITY;
const isNegativeZero = value => value === 0 && 1 / value === Number.NEGATIVE_INFINITY;

Options

Type: object

checkInfinity

Type: boolean
Default: true

Pass checkInfinity: false to disable check on Infinity.

Fail

// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": true}]
const foo = Infinity;
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": true}]
const foo = -Infinity;

Pass

// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": false}]
const foo = Infinity;
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": false}]
const foo = -Infinity;