Skip to content

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.

This rule was inspired by ESLint Core's prefer-exponentiation-operator, but additionally detects multiplication with the same operands.

/* eslint math/prefer-exponentiation-operator: 'error' */ /* ✓ GOOD */ x = a ** b; /* ✗ BAD */ x = Math.pow(a, b); /* ✓ GOOD */ x = a ** 3; /* ✗ BAD */ x = a * a * a;
Now loading...

🔧 Options

Nothing.

📚 Further reading

🚀 Version

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

🔍 Implementation