Skip to content

math/no-static-infinity-calculations

disallow static calculations that result in infinity

  • ⚙️ This rule is included in "plugin:math/recommended".
  • 💡 Some problems reported by this rule are manually fixable by editor suggestions.

📖 Rule Details

This rule disallows static calculations that result in infinity.

This rule enforces explicit use of Infinity or Number.POSITIVE_INFINITY/Number.NEGATIVE_INFINITY instead of calculations that implicitly produce infinity values.

Using explicit infinity values provides several benefits:

  • Clear intent: Makes it obvious that infinity is the intended result
  • Better readability: Reduces cognitive load when reading code
  • Consistency: Standardizes how infinite values are represented
  • Debugging clarity: Easier to identify intentional vs accidental infinity values
  • JSON compatibility awareness: Explicit infinity usage makes serialization behavior clear

This rule helps catch expressions that will always evaluate to positive or negative infinity at development time and suggests using explicit infinity constants instead.

Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

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

🔍 Implementation