💼 This rule is enabled in the ✅ recommended
config.
🔧💡 This rule is automatically fixable by the --fix
CLI option and manually fixable by editor suggestions.
Enforces the use of:
Number.parseInt()
overparseInt()
(fixable)Number.parseFloat()
overparseFloat()
(fixable)Number.isNaN()
overisNaN()
(they have slightly different behavior)Number.isFinite()
overisFinite()
(they have slightly different behavior)Number.NaN
overNaN
(fixable)Number.POSITIVE_INFINITY
overInfinity
(fixable)Number.NEGATIVE_INFINITY
over-Infinity
(fixable)
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);
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;
Type: object
Type: boolean
Default: true
Pass checkInfinity: false
to disable check on Infinity
.
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": true}]
const foo = Infinity;
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": true}]
const foo = -Infinity;
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": false}]
const foo = Infinity;
// eslint unicorn/prefer-number-properties: ["error", {"checkInfinity": false}]
const foo = -Infinity;