Skip to content

Commit 793d537

Browse files
committed
[Docs]: Recategorize rules in readme
1 parent 24bf594 commit 793d537

23 files changed

+99
-74
lines changed

README.md

+46-37
Large diffs are not rendered by default.

lib/rules/boolean-prop-naming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const messages = {
2222
module.exports = {
2323
meta: {
2424
docs: {
25-
category: 'Stylistic Issues',
25+
category: 'Best Practices',
2626
description: 'Enforces consistent naming for boolean props',
2727
recommended: false,
2828
url: docsUrl('boolean-prop-naming'),

lib/rules/button-has-type.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
meta: {
3333
docs: {
3434
description: 'Forbid "button" element without an explicit "type" attribute',
35-
category: 'Possible Errors',
35+
category: 'Best Practices',
3636
recommended: false,
3737
url: docsUrl('button-has-type'),
3838
},

lib/rules/destructuring-assignment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = {
5656
meta: {
5757
docs: {
5858
description: 'Enforce consistent usage of destructuring assignment of props, state, and context',
59-
category: 'Stylistic Issues',
59+
category: 'Best Practices',
6060
recommended: false,
6161
url: docsUrl('destructuring-assignment'),
6262
},

lib/rules/function-component-definition.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module.exports = {
102102
meta: {
103103
docs: {
104104
description: 'Standardize the way function component get defined',
105-
category: 'Stylistic Issues',
105+
category: 'Best Practices',
106106
recommended: false,
107107
url: docsUrl('function-component-definition'),
108108
},

lib/rules/jsx-boolean-value.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
meta: {
5959
docs: {
6060
description: 'Enforce boolean attributes notation in JSX',
61-
category: 'Stylistic Issues',
61+
category: 'Best Practices',
6262
recommended: false,
6363
url: docsUrl('jsx-boolean-value'),
6464
},

lib/rules/jsx-filename-extension.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
meta: {
3232
docs: {
3333
description: 'Restrict file extensions that may contain JSX',
34-
category: 'Stylistic Issues',
34+
category: 'Best Practices',
3535
recommended: false,
3636
url: docsUrl('jsx-filename-extension'),
3737
},

lib/rules/jsx-fragments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
meta: {
3232
docs: {
3333
description: 'Enforce shorthand or standard form for React fragments',
34-
category: 'Stylistic Issues',
34+
category: 'Best Practices',
3535
recommended: false,
3636
url: docsUrl('jsx-fragments'),
3737
},

lib/rules/jsx-handler-names.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
meta: {
2222
docs: {
2323
description: 'Enforce event handler naming conventions in JSX',
24-
category: 'Stylistic Issues',
24+
category: 'Best Practices',
2525
recommended: false,
2626
url: docsUrl('jsx-handler-names'),
2727
},

lib/rules/jsx-max-depth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
meta: {
2525
docs: {
2626
description: 'Validate JSX maximum depth',
27-
category: 'Stylistic Issues',
27+
category: 'Best Practices',
2828
recommended: false,
2929
url: docsUrl('jsx-max-depth'),
3030
},

lib/rules/jsx-no-useless-fragment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module.exports = {
8989
fixable: 'code',
9090
docs: {
9191
description: 'Disallow unnecessary fragments',
92-
category: 'Possible Errors',
92+
category: 'Best Practices',
9393
recommended: false,
9494
url: docsUrl('jsx-no-useless-fragment'),
9595
},

lib/rules/jsx-pascal-case.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = {
8080
meta: {
8181
docs: {
8282
description: 'Enforce PascalCase for user-defined JSX components',
83-
category: 'Stylistic Issues',
83+
category: 'Best Practices',
8484
recommended: false,
8585
url: docsUrl('jsx-pascal-case'),
8686
},

lib/rules/no-invalid-html-attribute.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ module.exports = {
533533
meta: {
534534
fixable: 'code',
535535
docs: {
536-
description: 'Forbid attribute with an invalid values`',
536+
description: 'Forbid attribute with an invalid values',
537537
category: 'Possible Errors',
538538
url: docsUrl('no-invalid-html-attribute'),
539539
},

lib/rules/no-multi-comp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
meta: {
2222
docs: {
2323
description: 'Prevent multiple component definition per file',
24-
category: 'Stylistic Issues',
24+
category: 'Best Practices',
2525
recommended: false,
2626
url: docsUrl('no-multi-comp'),
2727
},

lib/rules/no-set-state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
meta: {
2222
docs: {
2323
description: 'Prevent usage of setState',
24-
category: 'Stylistic Issues',
24+
category: 'Best Practices',
2525
recommended: false,
2626
url: docsUrl('no-set-state'),
2727
},

lib/rules/no-typos.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
meta: {
3232
docs: {
3333
description: 'Prevent common typos',
34-
category: 'Stylistic Issues',
34+
category: 'Best Practices',
3535
recommended: false,
3636
url: docsUrl('no-typos'),
3737
},

lib/rules/no-unstable-nested-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ module.exports = {
270270
meta: {
271271
docs: {
272272
description: 'Prevent creating unstable components inside components',
273-
category: 'Possible Errors',
273+
category: 'Best Practices',
274274
recommended: false,
275275
url: docsUrl('no-unstable-nested-components'),
276276
},

lib/rules/prefer-es6-class.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
meta: {
2323
docs: {
2424
description: 'Enforce ES5 or ES6 class for React Components',
25-
category: 'Stylistic Issues',
25+
category: 'Best Practices',
2626
recommended: false,
2727
url: docsUrl('prefer-es6-class'),
2828
},

lib/rules/prefer-exact-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
meta: {
2525
docs: {
2626
description: 'Prefer exact proptype definitions',
27-
category: 'Possible Errors',
27+
category: 'Best Practices',
2828
recommended: false,
2929
url: docsUrl('prefer-exact-props'),
3030
},

lib/rules/prefer-read-only-props.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
meta: {
3737
docs: {
3838
description: 'Require read-only props.',
39-
category: 'Stylistic Issues',
39+
category: 'Best Practices',
4040
recommended: false,
4141
url: docsUrl('prefer-read-only-props'),
4242
},

lib/rules/prefer-stateless-function.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
meta: {
2626
docs: {
2727
description: 'Enforce stateless components to be written as a pure function',
28-
category: 'Stylistic Issues',
28+
category: 'Best Practices',
2929
recommended: false,
3030
url: docsUrl('prefer-stateless-function'),
3131
},

lib/rules/state-in-constructor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
meta: {
2323
docs: {
2424
description: 'State initialization in an ES6 class component should be in a constructor',
25-
category: 'Stylistic Issues',
25+
category: 'Best Practices',
2626
recommended: false,
2727
url: docsUrl('state-in-constructor'),
2828
},

markdown.config.js

+32-16
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
const { rules } = require('./index');
66

7-
const ruleTableRows = Object.keys(rules)
8-
.sort()
9-
.map((id) => {
10-
const { meta } = rules[id];
11-
const { fixable, docs } = meta;
12-
return [
13-
docs.recommended ? '✔' : '',
14-
fixable ? '🔧' : '',
15-
`[react/${id}](docs/rules/${id}.md)`,
16-
docs.description,
17-
].join(' | ');
18-
});
7+
const buildRuleRow = (id) => {
8+
const { meta } = rules[id];
9+
const { fixable, docs } = meta;
10+
return [
11+
docs.recommended ? '✔' : '',
12+
fixable ? '🔧' : '',
13+
`[react/${id}](docs/rules/${id}.md)`,
14+
docs.description,
15+
].join(' | ');
16+
};
1917

2018
const buildRulesTable = (rows) => {
2119
const header = '✔ | 🔧 | Rule | Description';
@@ -26,13 +24,31 @@ const buildRulesTable = (rows) => {
2624
.join('\n');
2725
};
2826

29-
const BASIC_RULES = () => buildRulesTable(ruleTableRows.filter((rule) => !rule.includes('react/jsx-')));
30-
const JSX_RULES = () => buildRulesTable(ruleTableRows.filter((rule) => rule.includes('react/jsx-')));
27+
const buildTableOfCategory = (category) => buildRulesTable(
28+
Object.keys(rules)
29+
.sort()
30+
.filter((rule) => rules[rule].meta.docs.category === category)
31+
.map((r) => buildRuleRow(r))
32+
);
33+
34+
for (const rule in rules) {
35+
if (
36+
!['Possible Errors', 'Best Practices', 'Stylistic Issues'].includes(
37+
rules[rule].meta.docs.category
38+
)
39+
) {
40+
console.error(
41+
`Rule ${rule} has wrong category: ${rules[rule].meta.docs.category}`
42+
);
43+
process.exit(1);
44+
}
45+
}
3146

3247
module.exports = {
3348
transforms: {
34-
BASIC_RULES,
35-
JSX_RULES,
49+
POSSIBLE_ERRORS_RULES: () => buildTableOfCategory('Possible Errors'),
50+
BEST_PRACTICES_RULES: () => buildTableOfCategory('Best Practices'),
51+
STYLISTIC_ISSUES_RULES: () => buildTableOfCategory('Stylistic Issues'),
3652
},
3753
callback: () => {
3854
console.log('The auto-generating of rules finished!');

0 commit comments

Comments
 (0)