Skip to content
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

Deprecate prefer-exponentiation-operator rule #484

2 changes: 2 additions & 0 deletions docs/rules/prefer-exponentiation-operator.md
@@ -1,5 +1,7 @@
# Prefer the exponentiation operator over `Math.pow()`

**This rule have been deprecated, please use [`prefer-exponentiation-operator`](https://eslint.org/docs/rules/prefer-exponentiation-operator) instead.**

Enforces the use of the [exponentiation operator](http://2ality.com/2016/02/exponentiation-operator.html) over [`Math.pow()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow).

This rule is fixable.
Expand Down
7 changes: 5 additions & 2 deletions readme.md
Expand Up @@ -64,7 +64,6 @@ Configure it in `package.json`.
"unicorn/prefer-add-event-listener": "error",
"unicorn/prefer-dataset": "error",
"unicorn/prefer-event-key": "error",
"unicorn/prefer-exponentiation-operator": "error",
"unicorn/prefer-flat-map": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-modern-dom-apis": "error",
Expand Down Expand Up @@ -118,7 +117,6 @@ Configure it in `package.json`.
- [prefer-add-event-listener](docs/rules/prefer-add-event-listener.md) - Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions. *(partly fixable)*
- [prefer-dataset](docs/rules/prefer-dataset.md) - Prefer using `.dataset` on DOM elements over `.setAttribute(…)`. *(fixable)*
- [prefer-event-key](docs/rules/prefer-event-key.md) - Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`. *(partly fixable)*
- [prefer-exponentiation-operator](docs/rules/prefer-exponentiation-operator.md) - Prefer the exponentiation operator over `Math.pow()` *(fixable)*
- [prefer-flat-map](docs/rules/prefer-flat-map.md) - Prefer `.flatMap(…)` over `.map(…).flat()`. *(fixable)*
- [prefer-includes](docs/rules/prefer-includes.md) - Prefer `.includes()` over `.indexOf()` when checking for existence or non-existence. *(fixable)*
- [prefer-modern-dom-apis](docs/rules/prefer-modern-dom-apis.md) - Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`. *(fixable)*
Expand All @@ -137,6 +135,11 @@ Configure it in `package.json`.
- [regex-shorthand](docs/rules/regex-shorthand.md) - Enforce the use of regex shorthands to improve readability. *(fixable)*
- [throw-new-error](docs/rules/throw-new-error.md) - Require `new` when throwing an error. *(fixable)*

## Deprecated Rules

|Deprecated rule|Replaced by|Rule Details|
|:--|:--|:--|
|[unicorn/prefer-exponentiation-operator](docs/rules/prefer-exponentiation-operator.md)|[prefer-exponentiation-operator](https://eslint.org/docs/rules/prefer-exponentiation-operator)|Prefer the exponentiation operator over `Math.pow()`|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use a table for this. Markdown tables are annoying to edit and comes with little benefit here. Not every deprecated rule will have a replacement either. Better to just use a plain list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


## Recommended config

Expand Down
6 changes: 5 additions & 1 deletion rules/prefer-exponentiation-operator.js
Expand Up @@ -58,5 +58,9 @@ module.exports = {
url: getDocumentationUrl(__filename)
},
fixable: 'code'
}
},
deprecated: true,
replacedBy: [
'prefer-exponentiation-operator'
]
};
15 changes: 11 additions & 4 deletions test/package.js
Expand Up @@ -15,6 +15,10 @@ const ignoredRules = [
'no-nested-ternary'
];

const deprecatedRules = [
'prefer-exponentiation-operator'
];

const testSorted = (t, actualOrder, sourceName) => {
actualOrder = actualOrder.filter(x => !ignoredRules.includes(x));
const sortedOrder = actualOrder.slice(0).sort();
Expand Down Expand Up @@ -77,14 +81,17 @@ test('Every rule is defined in readme.md usage and list of rules in alphabetical
}
} while (match);

for (const file of ruleFiles) {
const name = path.basename(file, '.js');
const availableRules = ruleFiles
.map(file => path.basename(file, '.js'))
.filter(name => !deprecatedRules.includes(name));

for (const name of availableRules) {
t.truthy(usageRules[`unicorn/${name}`], `'${name}' is not described in the readme.md ## Usage`);
t.truthy(rules.includes(name), `'${name}' is not described in the readme.md ## Rules`);
}

t.is(Object.keys(usageRules).length - ignoredRules.length, ruleFiles.length, 'There are more rules in readme.md ## Usage than rule files.');
t.is(Object.keys(rules).length, ruleFiles.length, 'There are more rules in readme.md ## Rules than rule files.');
t.is(Object.keys(usageRules).length - ignoredRules.length, availableRules.length, 'There are more rules in readme.md ## Usage than rule files.');
t.is(Object.keys(rules).length, availableRules.length, 'There are more rules in readme.md ## Rules than rule files.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth it to add a check that ensures deprecated rules are described in the readme?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's really nessary.


testSorted(t, Object.keys(usageRules), 'readme.md ## Usage rules');
testSorted(t, rules, 'readme.md ## Rules');
Expand Down
5 changes: 5 additions & 0 deletions test/prefer-exponentiation-operator.js
Expand Up @@ -10,6 +10,11 @@ const ruleTester = avaRuleTester(test, {

const message = 'Prefer the exponentiation operator over `Math.pow()`.';

test('deprecated', t => {
t.true(rule.deprecated);
t.deepEqual(rule.replacedBy, ['prefer-exponentiation-operator']);
});

ruleTester.run('prefer-exponentiation-operator', rule, {
valid: [
'a ** b;',
Expand Down