math/prefer-exponentiation-operator
enforce the use of exponentiation (
**
) operator instead of other calculations
- 🔧 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 exponentiation (**
) operator instead of other calculations.
The exponentiation operator (**
) provides several advantages over alternatives:
- Readability: More concise and mathematically intuitive
- Performance: Often better optimized by JavaScript engines
- Consistency: Standard ES2016+ syntax for exponentiation
- Type Safety: Better behavior with edge cases compared to
Math.pow
This rule was inspired by ESLint Core's prefer-exponentiation-operator, but additionally detects multiplication with the same operands.
🔧 Options
Nothing.
📚 Further reading
👫 Related rules
🚀 Version
This rule was introduced in eslint-plugin-math v0.6.0