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

[Docs] Standardize deprecated rule notice #3364

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [Docs] [`jsx-no-target-blank`]: Fix link to link-type-noreferrer ([#3319][] @Luccasoli)
* [Docs] document which rules provide suggestions ([#3359][] @bmish)
* [Docs] Consistent rule descriptions and doc sections ([#3361][] @bmish)
* [Docs] Standardize deprecated rule notice ([#3364][] @bmish)

[#3364]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3364
[#3361]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3361
[#3359]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3359
[#3355]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3355
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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