New Rule: prefer-exponentiation-operator
See original GitHub issuePlease describe what the rule should do:
ES2016 adds an exponentiation operator **
; this may be preferred over using Math.pow()
. The rule should disallow the use of the Math.pow()
function, in favor of using **
.
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [ ] Warns about a potential error [x] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
// Good
const a = 5 ** 7
// Bad
const a = Math.pow(5, 7)
Why should this rule be included in ESLint (instead of a plugin)?
This is a ES2016 feature, which can replace an older way of doing things. There should be a rule to force upgrading code; similar to how ESLint has no-var
, prefer-spread
, etc.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:13 (10 by maintainers)
Top Results From Across the Web
prefer-exponentiation-operator - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Disallow the use of Math.pow in favor of the ** operator (prefer ...
This rule disallows calls to Math.pow and suggests using the ** operator instead. Examples of incorrect code for this rule: /*eslint prefer-exponentiation ......
Read more >Exponentiation (**) - JavaScript - MDN Web Docs - Mozilla
The exponentiation ( ** ) operator returns the result of raising the first operand to the power of the second operand.
Read more >Prefer-exponentiation-operator - ESLint - W3cubDocs
This rule disallows calls to Math.pow and suggests using the ** operator instead. Examples of incorrect code for this rule: /*eslint prefer-exponentiation- ...
Read more >unit testing - eslint rule forces exponentiation operator vs Math ...
... in https://2ality.com/2016/02/exponentiation-operator.html, it's final in es2016, so just set eslint rule "parseOptions" like below:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll champion this proposal. I like the rule name
prefer-exponentiation-operator
and it has autofix. That rule will encourage to learn the new syntax.https://stackoverflow.com/questions/41679191/why-is-math-pow-sometimes-not-equal-to-in-javascript
According to this questions, use
Math.pow()
is safer than**
.