Skip to content

Commit

Permalink
[Chore] Standardize deprecated rule notice
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Aug 21, 2022
1 parent 13d23b8 commit 61c1d3f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -218,7 +218,7 @@ Enable the rules that you would like to use.
| | | | [react/jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md) | Disallow JSX prop spreading |
| | | | [react/jsx-sort-default-props](docs/rules/jsx-sort-default-props.md) | Enforce defaultProps declarations alphabetical sorting |
| | 🔧 | | [react/jsx-sort-props](docs/rules/jsx-sort-props.md) | Enforce props alphabetical sorting |
| | 🔧 | | [react/jsx-space-before-closing](docs/rules/jsx-space-before-closing.md) | Enforce spacing before closing bracket in JSX |
| | 🔧 | | [react/jsx-space-before-closing](docs/rules/jsx-space-before-closing.md) | Enforce spacing before closing bracket in JSX. ❌ This rule is deprecated. |
| | 🔧 | | [react/jsx-tag-spacing](docs/rules/jsx-tag-spacing.md) | Enforce whitespace in and around the JSX opening and closing brackets |
|| | | [react/jsx-uses-react](docs/rules/jsx-uses-react.md) | Disallow React to be incorrectly marked as unused |
|| | | [react/jsx-uses-vars](docs/rules/jsx-uses-vars.md) | Disallow variables used in JSX to be incorrectly marked as unused |
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/jsx-space-before-closing.md
@@ -1,8 +1,8 @@
# Enforce spacing before closing bracket in JSX (react/jsx-space-before-closing)

🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
This rule is deprecated. Please use the `"beforeSelfClosing"` option of the [jsx-tag-spacing](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md) rule instead.

**Deprecation notice**: This rule is deprecated. Please use the `"beforeSelfClosing"` option of the [jsx-tag-spacing](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md) rule instead.
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.

Enforce or forbid spaces before the closing bracket of self-closing JSX elements.

Expand Down
2 changes: 1 addition & 1 deletion markdown.config.js
Expand Up @@ -14,7 +14,7 @@ const ruleTableRows = Object.keys(rules)
fixable ? '🔧' : '',
hasSuggestions ? '💡' : '',
`[react/${id}](docs/rules/${id}.md)`,
docs.description,
`${docs.description}${meta.deprecated ? '. ❌ This rule is deprecated.' : ''}`,
].join(' | ');
});

Expand Down
14 changes: 13 additions & 1 deletion tests/index.js
Expand Up @@ -24,6 +24,7 @@ describe('all rule files should be exported by the plugin', () => {

describe('rule documentation files have the correct content', () => {
const MESSAGES = {
deprecated: '❌ This rule is deprecated.',
fixable: '🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.',
hasSuggestions: '💡 This rule provides editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).',
};
Expand All @@ -42,6 +43,11 @@ describe('rule documentation files have the correct content', () => {
// Decide which notices should be shown at the top of the doc.
const expectedNotices = [];
const unexpectedNotices = [];
if (rule.meta.deprecated) {
expectedNotices.push('deprecated');
} else {
unexpectedNotices.push('deprecated');
}
if (rule.meta.fixable) {
expectedNotices.push('fixable');
} else {
Expand All @@ -57,7 +63,13 @@ describe('rule documentation files have the correct content', () => {
let currentLineNumber = 1;
expectedNotices.forEach((expectedNotice) => {
assert.strictEqual(documentLines[currentLineNumber], '', `includes blank line ahead of ${expectedNotice} notice`);
assert.strictEqual(documentLines[currentLineNumber + 1], MESSAGES[expectedNotice], `includes ${expectedNotice} notice`);
if (expectedNotice === 'deprecated' && documentLines[currentLineNumber + 1] !== MESSAGES[expectedNotice] && documentLines[currentLineNumber + 1].startsWith(MESSAGES[expectedNotice])) {
// Allow additional rule-specific information at the end of the deprecation notice line.
assert.ok(true, `includes ${expectedNotice} notice`);
} else {
// Otherwise, just check the whole line.
assert.strictEqual(documentLines[currentLineNumber + 1], MESSAGES[expectedNotice], `includes ${expectedNotice} notice`);
}
currentLineNumber += 2;
});

Expand Down

0 comments on commit 61c1d3f

Please sign in to comment.