-
-
Notifications
You must be signed in to change notification settings - Fork 420
Add prefer-exponentiation-operator rule #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prefer-exponentiation-operator rule #185
Conversation
No, it should be enabled.
Yes, to the bottom of the list in the readme and the recommended config. |
| invalid: [ | ||
| { | ||
| code: 'const x = Math.pow(2, 4);', | ||
| errors: [{message: 'Prefer the exponentiation operator over `Math.pow()`.', column: 11, line: 1}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a method like this so you don't have to repeat the error for invalid item. I don't think there's any point in specifying column/line except for the test where there are multiple Math.pow() in one test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there aren't any parameters, I just made it a constant.
| context.report({ | ||
| node, | ||
| message: 'Prefer the exponentiation operator over `Math.pow()`.', | ||
| fix: fixer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the fixer method to a top-level function too, for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you need fixer, context and node to run the fix, I'm not sure moving it out really helps much. I gave it a shot; let me know what you think.
|
Perfect. Thanks for implementing this :) |
Had two questions:
off?readme.md?Fixes #173.