Skip to content

Conversation

@MrHen
Copy link
Contributor

@MrHen MrHen commented Aug 19, 2018

Had two questions:

  • Should the rule be added to the recommended configuration as off?
  • Should new rules always be added to the bottom of the rule list in readme.md?

Fixes #173.

@sindresorhus
Copy link
Owner

Should the rule be added to the recommended configuration as off?

No, it should be enabled.

Should new rules always be added to the bottom of the rule list in readme.md?

Yes, to the bottom of the list in the readme and the recommended config.

@sindresorhus sindresorhus changed the title prefer-exponentiation-operator rule Add prefer-exponentiation-operator rule Aug 20, 2018
invalid: [
{
code: 'const x = Math.pow(2, 4);',
errors: [{message: 'Prefer the exponentiation operator over `Math.pow()`.', column: 11, line: 1}],
Copy link
Owner

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.

Copy link
Contributor Author

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 => {
Copy link
Owner

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.

Copy link
Contributor Author

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.

@sindresorhus sindresorhus merged commit 9f7f811 into sindresorhus:master Aug 23, 2018
@sindresorhus
Copy link
Owner

Perfect. Thanks for implementing this :)

@MrHen MrHen deleted the feature/173-prefer-exponentiation-operator branch August 23, 2018 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants