Skip to content

Commit

Permalink
Simplify rule deprecation (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Dec 23, 2020
1 parent a1b60ad commit 72e0390
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 58 deletions.
9 changes: 9 additions & 0 deletions docs/deprecated-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Deprecated Rules

## prefer-exponentiation-operator

This rule is deprecated in favor of the built-in ESLint [`prefer-exponentiation-operator`](https://eslint.org/docs/rules/prefer-exponentiation-operator) rule.

## regex-shorthand

This rule was renamed to [`better-regex`](rules/better-regex.md).
1 change: 0 additions & 1 deletion docs/rules/prefer-exponentiation-operator.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/rules/regex-shorthand.md

This file was deleted.

12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
'use strict';
const path = require('path');
const importModules = require('import-modules');
const createDeprecatedRules = require('./rules/utils/create-deprecated-rules');

const deprecatedRules = createDeprecatedRules({
// {ruleId: ReplacementRuleId | ReplacementRuleId[]}, if no replacement, use `{ruleId: []}`
'prefer-exponentiation-operator': 'prefer-exponentiation-operator',
'regex-shorthand': 'unicorn/better-regex'
});

module.exports = {
rules: importModules(path.resolve(__dirname, 'rules'), {camelize: false}),
rules: {
...importModules(path.resolve(__dirname, 'rules'), {camelize: false}),
...deprecatedRules
},
configs: {
recommended: {
env: {
Expand Down
3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ Configure it in `package.json`.

## Deprecated Rules

- [prefer-exponentiation-operator](docs/rules/prefer-exponentiation-operator.md) - Use the built-in ESLint [`prefer-exponentiation-operator`](https://eslint.org/docs/rules/prefer-exponentiation-operator) rule instead.
- [regex-shorthand](docs/rules/regex-shorthand.md) - Renamed to [`better-regex`](docs/rules/better-regex.md).
See [docs/deprecated-rules.md](docs/deprecated-rules.md)

## Recommended config

Expand Down
19 changes: 0 additions & 19 deletions rules/prefer-exponentiation-operator.js

This file was deleted.

19 changes: 0 additions & 19 deletions rules/regex-shorthand.js

This file was deleted.

21 changes: 21 additions & 0 deletions rules/utils/create-deprecated-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const packageJson = require('../../package');
const repoUrl = 'https://github.com/sindresorhus/eslint-plugin-unicorn';

function createDeprecatedRules(data) {
const rules = {};
for (const [ruleId, replacedBy = []] of Object.entries(data)) {
rules[ruleId] = {
create: () => ({}),
meta: {
docs: {
url: `${repoUrl}/blob/v${packageJson.version}/docs/deprecated-rules.md#${ruleId}`
},
deprecated: true,
replacedBy: Array.isArray(replacedBy) ? replacedBy : [replacedBy]
}
};
}
}

module.exports = createDeprecatedRules;
2 changes: 1 addition & 1 deletion test/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test('Every rule is defined in index file in alphabetical order', t => {
'There are more exported rules than rule files.'
);
t.is(
Object.keys(index.configs.recommended.rules).length - ignoredRules.length,
Object.keys(index.configs.recommended.rules).length - deprecatedRules.length - ignoredRules.length,
ruleFiles.length - deprecatedRules.length,
'There are more exported rules in the recommended config than rule files.'
);
Expand Down
7 changes: 0 additions & 7 deletions test/prefer-exponentiation-operator.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/regex-shorthand.js

This file was deleted.

0 comments on commit 72e0390

Please sign in to comment.