Skip to content

Commit

Permalink
[Docs]: Recategorize rules in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Mar 5, 2022
1 parent 24bf594 commit 793d537
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 74 deletions.
83 changes: 46 additions & 37 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const messages = {
module.exports = {
meta: {
docs: {
category: 'Stylistic Issues',
category: 'Best Practices',
description: 'Enforces consistent naming for boolean props',
recommended: false,
url: docsUrl('boolean-prop-naming'),
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/button-has-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
meta: {
docs: {
description: 'Forbid "button" element without an explicit "type" attribute',
category: 'Possible Errors',
category: 'Best Practices',
recommended: false,
url: docsUrl('button-has-type'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce consistent usage of destructuring assignment of props, state, and context',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('destructuring-assignment'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module.exports = {
meta: {
docs: {
description: 'Standardize the way function component get defined',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('function-component-definition'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-boolean-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce boolean attributes notation in JSX',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-boolean-value'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-filename-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
meta: {
docs: {
description: 'Restrict file extensions that may contain JSX',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-filename-extension'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce shorthand or standard form for React fragments',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-fragments'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce event handler naming conventions in JSX',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-handler-names'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-max-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
meta: {
docs: {
description: 'Validate JSX maximum depth',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-max-depth'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-no-useless-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = {
fixable: 'code',
docs: {
description: 'Disallow unnecessary fragments',
category: 'Possible Errors',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-no-useless-fragment'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce PascalCase for user-defined JSX components',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('jsx-pascal-case'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-html-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ module.exports = {
meta: {
fixable: 'code',
docs: {
description: 'Forbid attribute with an invalid values`',
description: 'Forbid attribute with an invalid values',
category: 'Possible Errors',
url: docsUrl('no-invalid-html-attribute'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-multi-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
meta: {
docs: {
description: 'Prevent multiple component definition per file',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('no-multi-comp'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
meta: {
docs: {
description: 'Prevent usage of setState',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('no-set-state'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
meta: {
docs: {
description: 'Prevent common typos',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('no-typos'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unstable-nested-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ module.exports = {
meta: {
docs: {
description: 'Prevent creating unstable components inside components',
category: 'Possible Errors',
category: 'Best Practices',
recommended: false,
url: docsUrl('no-unstable-nested-components'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-es6-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce ES5 or ES6 class for React Components',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('prefer-es6-class'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-exact-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
meta: {
docs: {
description: 'Prefer exact proptype definitions',
category: 'Possible Errors',
category: 'Best Practices',
recommended: false,
url: docsUrl('prefer-exact-props'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-read-only-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
meta: {
docs: {
description: 'Require read-only props.',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('prefer-read-only-props'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-stateless-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
meta: {
docs: {
description: 'Enforce stateless components to be written as a pure function',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('prefer-stateless-function'),
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/state-in-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
meta: {
docs: {
description: 'State initialization in an ES6 class component should be in a constructor',
category: 'Stylistic Issues',
category: 'Best Practices',
recommended: false,
url: docsUrl('state-in-constructor'),
},
Expand Down
48 changes: 32 additions & 16 deletions markdown.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

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

const ruleTableRows = Object.keys(rules)
.sort()
.map((id) => {
const { meta } = rules[id];
const { fixable, docs } = meta;
return [
docs.recommended ? '✔' : '',
fixable ? '🔧' : '',
`[react/${id}](docs/rules/${id}.md)`,
docs.description,
].join(' | ');
});
const buildRuleRow = (id) => {
const { meta } = rules[id];
const { fixable, docs } = meta;
return [
docs.recommended ? '✔' : '',
fixable ? '🔧' : '',
`[react/${id}](docs/rules/${id}.md)`,
docs.description,
].join(' | ');
};

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

const BASIC_RULES = () => buildRulesTable(ruleTableRows.filter((rule) => !rule.includes('react/jsx-')));
const JSX_RULES = () => buildRulesTable(ruleTableRows.filter((rule) => rule.includes('react/jsx-')));
const buildTableOfCategory = (category) => buildRulesTable(
Object.keys(rules)
.sort()
.filter((rule) => rules[rule].meta.docs.category === category)
.map((r) => buildRuleRow(r))
);

for (const rule in rules) {
if (
!['Possible Errors', 'Best Practices', 'Stylistic Issues'].includes(
rules[rule].meta.docs.category
)
) {
console.error(
`Rule ${rule} has wrong category: ${rules[rule].meta.docs.category}`
);
process.exit(1);
}
}

module.exports = {
transforms: {
BASIC_RULES,
JSX_RULES,
POSSIBLE_ERRORS_RULES: () => buildTableOfCategory('Possible Errors'),
BEST_PRACTICES_RULES: () => buildTableOfCategory('Best Practices'),
STYLISTIC_ISSUES_RULES: () => buildTableOfCategory('Stylistic Issues'),
},
callback: () => {
console.log('The auto-generating of rules finished!');
Expand Down

0 comments on commit 793d537

Please sign in to comment.