close

prefer-number-properties

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-number-properties': 'error',
    },
  },
]);

Rule Details

Prefer Number static properties and methods over global number-related properties and functions.

Examples of incorrect code for this rule:

const value = parseInt("10", 2);
const number = parseFloat("10.5");
const finite = isFinite(value);
const missing = Number.isNaN(NaN);

Examples of correct code for this rule:

const value = Number.parseInt("10", 2);
const number = Number.parseFloat("10.5");
const finite = Number.isFinite(value);
const missing = Number.isNaN(Number.NaN);

Options

checkInfinity

Type: boolean
Default: false

When true, the rule also checks global Infinity and -Infinity.

{ "unicorn/prefer-number-properties": ["error", { "checkInfinity": true }] }

Examples of incorrect code for this option:

const upperBound = Infinity;
const lowerBound = -Infinity;

Examples of correct code for this option:

const upperBound = Number.POSITIVE_INFINITY;
const lowerBound = Number.NEGATIVE_INFINITY;

checkNaN

Type: boolean
Default: true

When false, the rule does not check global NaN.

{ "unicorn/prefer-number-properties": ["error", { "checkNaN": false }] }

Examples of correct code for this option:

const missing = NaN;

Original Documentation