question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule: prefer-exponentiation-operator

See original GitHub issue

Please 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:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

8reactions
mysticateacommented, Jun 22, 2018

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.

4reactions
izaylcommented, Feb 1, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found