Skip to content

math/prefer-number-is-finite

enforce the use of Number.isFinite() instead of other checking ways

  • ⚙️ This rule is included in "plugin:math/recommended".
  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.
  • 💡 Some problems reported by this rule are manually fixable by editor suggestions.

📖 Rule Details

This rule aims to enforce the use of Number.isFinite() instead of other checking ways.

Number.isFinite() is the preferred method for checking if a value is a finite number because:

  • Type safety: Only returns true for actual finite numbers, not for strings that can be converted
  • No type coercion: Unlike global isFinite(), it doesn't convert values to numbers first
  • Clear semantics: Explicitly checks for finite numeric values
  • Performance: Direct type and value checking without conversion overhead
  • Consistency: Part of the modern Number API family
Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-math v0.4.0

🔍 Implementation