math/no-static-nan-calculations
disallow static calculations that result in NaN
- ⚙️ 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 NaN (Not a Number).
This rule enforces explicit use of NaN
or Number.NaN
instead of calculations that implicitly produce NaN values.
Using explicit NaN values provides several benefits:
- Clear intent: Makes it obvious that NaN is the intended result
- Better readability: Reduces cognitive load when reading code
- Consistency: Standardizes how NaN values are represented
- Debugging clarity: Easier to identify intentional vs accidental NaN values
- Code maintainability: Explicit NaN usage is more self-documenting
This rule helps catch expressions that will always evaluate to NaN at development time and suggests using explicit NaN constants instead.
🔧 Options
Nothing.
📚 Further reading
👫 Related rules
🚀 Version
This rule was introduced in eslint-plugin-math v0.5.0