diff --git a/README.md b/README.md index b1efbcd0de..3cf8573ccf 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,32 @@ Enable the rules that you would like to use. ✔: Enabled in the [`recommended`](#recommended) configuration.\ 🔧: Fixable with [`eslint --fix`](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems). - +## Possible Errors + + +| ✔ | 🔧 | Rule | Description | +| :---: | :---: | :--- | :--- | +| ✔ | | [react/jsx-key](docs/rules/jsx-key.md) | Report missing `key` props in iterators/collection literals | +| ✔ | | [react/jsx-no-comment-textnodes](docs/rules/jsx-no-comment-textnodes.md) | Comments inside children section of tag should be placed inside braces | +| ✔ | | [react/jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md) | Enforce no duplicate props | +| ✔ | | [react/jsx-no-undef](docs/rules/jsx-no-undef.md) | Disallow undeclared variables in JSX | +| | | [react/no-access-state-in-setstate](docs/rules/no-access-state-in-setstate.md) | Reports when this.state is accessed within setState | +| ✔ | | [react/no-danger-with-children](docs/rules/no-danger-with-children.md) | Report when a DOM element is using both children and dangerouslySetInnerHTML | +| ✔ | | [react/no-direct-mutation-state](docs/rules/no-direct-mutation-state.md) | Prevent direct mutation of this.state | +| | 🔧 | [react/no-invalid-html-attribute](docs/rules/no-invalid-html-attribute.md) | Forbid attribute with an invalid values | +| | | [react/no-namespace](docs/rules/no-namespace.md) | Enforce that namespaces are not used in React elements | +| | | [react/no-redundant-should-component-update](docs/rules/no-redundant-should-component-update.md) | Flag shouldComponentUpdate when extending PureComponent | +| | | [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md) | Report "this" being used in stateless components | +| ✔ | | [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md) | Detect unescaped HTML entities, which might represent malformed tags | +| ✔ | 🔧 | [react/no-unknown-property](docs/rules/no-unknown-property.md) | Prevent usage of unknown DOM property | +| ✔ | | [react/react-in-jsx-scope](docs/rules/react-in-jsx-scope.md) | Prevent missing React when using JSX | +| ✔ | | [react/require-render-return](docs/rules/require-render-return.md) | Enforce ES5 or ES6 class for returning value in render function | +| | | [react/style-prop-object](docs/rules/style-prop-object.md) | Enforce style prop value is an object | + + +## Best Practices + + | ✔ | 🔧 | Rule | Description | | :---: | :---: | :--- | :--- | | | | [react/boolean-prop-naming](docs/rules/boolean-prop-naming.md) | Enforces consistent naming for boolean props | @@ -133,30 +158,35 @@ Enable the rules that you would like to use. | | 🔧 | [react/function-component-definition](docs/rules/function-component-definition.md) | Standardize the way function component get defined | | | | [react/hook-use-state](docs/rules/hook-use-state.md) | Ensure symmetric naming of useState hook value and setter variables | | | | [react/iframe-missing-sandbox](docs/rules/iframe-missing-sandbox.md) | Enforce sandbox attribute on iframe elements | -| | | [react/no-access-state-in-setstate](docs/rules/no-access-state-in-setstate.md) | Reports when this.state is accessed within setState | +| | 🔧 | [react/jsx-boolean-value](docs/rules/jsx-boolean-value.md) | Enforce boolean attributes notation in JSX | +| | | [react/jsx-filename-extension](docs/rules/jsx-filename-extension.md) | Restrict file extensions that may contain JSX | +| | 🔧 | [react/jsx-fragments](docs/rules/jsx-fragments.md) | Enforce shorthand or standard form for React fragments | +| | | [react/jsx-handler-names](docs/rules/jsx-handler-names.md) | Enforce event handler naming conventions in JSX | +| | | [react/jsx-max-depth](docs/rules/jsx-max-depth.md) | Validate JSX maximum depth | +| | | [react/jsx-no-bind](docs/rules/jsx-no-bind.md) | Prevents usage of Function.prototype.bind and arrow functions in React component props | +| | | [react/jsx-no-constructed-context-values](docs/rules/jsx-no-constructed-context-values.md) | Prevents JSX context provider values from taking values that will cause needless rerenders. | +| | | [react/jsx-no-script-url](docs/rules/jsx-no-script-url.md) | Forbid `javascript:` URLs | +| ✔ | 🔧 | [react/jsx-no-target-blank](docs/rules/jsx-no-target-blank.md) | Forbid `target="_blank"` attribute without `rel="noreferrer"` | +| | 🔧 | [react/jsx-no-useless-fragment](docs/rules/jsx-no-useless-fragment.md) | Disallow unnecessary fragments | +| | | [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md) | Enforce PascalCase for user-defined JSX components | +| | | [react/jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md) | Prevent JSX prop spreading | +| ✔ | | [react/jsx-uses-react](docs/rules/jsx-uses-react.md) | Prevent React to be marked as unused | +| ✔ | | [react/jsx-uses-vars](docs/rules/jsx-uses-vars.md) | Prevent variables used in JSX to be marked as unused | | | | [react/no-adjacent-inline-elements](docs/rules/no-adjacent-inline-elements.md) | Prevent adjacent inline elements not separated by whitespace. | | | | [react/no-array-index-key](docs/rules/no-array-index-key.md) | Prevent usage of Array index in keys | | | 🔧 | [react/no-arrow-function-lifecycle](docs/rules/no-arrow-function-lifecycle.md) | Lifecycle methods should be methods on the prototype, not class fields | | ✔ | | [react/no-children-prop](docs/rules/no-children-prop.md) | Prevent passing of children as props. | | | | [react/no-danger](docs/rules/no-danger.md) | Prevent usage of dangerous JSX props | -| ✔ | | [react/no-danger-with-children](docs/rules/no-danger-with-children.md) | Report when a DOM element is using both children and dangerouslySetInnerHTML | | ✔ | | [react/no-deprecated](docs/rules/no-deprecated.md) | Prevent usage of deprecated methods | | | | [react/no-did-mount-set-state](docs/rules/no-did-mount-set-state.md) | Prevent usage of setState in componentDidMount | | | | [react/no-did-update-set-state](docs/rules/no-did-update-set-state.md) | Prevent usage of setState in componentDidUpdate | -| ✔ | | [react/no-direct-mutation-state](docs/rules/no-direct-mutation-state.md) | Prevent direct mutation of this.state | | ✔ | | [react/no-find-dom-node](docs/rules/no-find-dom-node.md) | Prevent usage of findDOMNode | -| | 🔧 | [react/no-invalid-html-attribute](docs/rules/no-invalid-html-attribute.md) | Forbid attribute with an invalid values` | | ✔ | | [react/no-is-mounted](docs/rules/no-is-mounted.md) | Prevent usage of isMounted | | | | [react/no-multi-comp](docs/rules/no-multi-comp.md) | Prevent multiple component definition per file | -| | | [react/no-namespace](docs/rules/no-namespace.md) | Enforce that namespaces are not used in React elements | -| | | [react/no-redundant-should-component-update](docs/rules/no-redundant-should-component-update.md) | Flag shouldComponentUpdate when extending PureComponent | | ✔ | | [react/no-render-return-value](docs/rules/no-render-return-value.md) | Prevent usage of the return value of React.render | | | | [react/no-set-state](docs/rules/no-set-state.md) | Prevent usage of setState | | ✔ | | [react/no-string-refs](docs/rules/no-string-refs.md) | Prevent string definitions for references and prevent referencing this.refs | -| | | [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md) | Report "this" being used in stateless components | | | | [react/no-typos](docs/rules/no-typos.md) | Prevent common typos | -| ✔ | | [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md) | Detect unescaped HTML entities, which might represent malformed tags | -| ✔ | 🔧 | [react/no-unknown-property](docs/rules/no-unknown-property.md) | Prevent usage of unknown DOM property | | | | [react/no-unsafe](docs/rules/no-unsafe.md) | Prevent usage of unsafe lifecycle methods | | | | [react/no-unstable-nested-components](docs/rules/no-unstable-nested-components.md) | Prevent creating unstable components inside components | | | | [react/no-unused-class-component-methods](docs/rules/no-unused-class-component-methods.md) | Prevent declaring unused methods of component class | @@ -168,25 +198,17 @@ Enable the rules that you would like to use. | | 🔧 | [react/prefer-read-only-props](docs/rules/prefer-read-only-props.md) | Require read-only props. | | | | [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md) | Enforce stateless components to be written as a pure function | | ✔ | | [react/prop-types](docs/rules/prop-types.md) | Prevent missing props validation in a React component definition | -| ✔ | | [react/react-in-jsx-scope](docs/rules/react-in-jsx-scope.md) | Prevent missing React when using JSX | | | | [react/require-default-props](docs/rules/require-default-props.md) | Enforce a defaultProps definition for every prop that is not a required prop. | | | | [react/require-optimization](docs/rules/require-optimization.md) | Enforce React components to have a shouldComponentUpdate method | -| ✔ | | [react/require-render-return](docs/rules/require-render-return.md) | Enforce ES5 or ES6 class for returning value in render function | -| | 🔧 | [react/self-closing-comp](docs/rules/self-closing-comp.md) | Prevent extra closing tags for components without children | -| | | [react/sort-comp](docs/rules/sort-comp.md) | Enforce component methods order | -| | | [react/sort-prop-types](docs/rules/sort-prop-types.md) | Enforce propTypes declarations alphabetical sorting | | | | [react/state-in-constructor](docs/rules/state-in-constructor.md) | State initialization in an ES6 class component should be in a constructor | -| | | [react/static-property-placement](docs/rules/static-property-placement.md) | Defines where React component static properties should be positioned. | -| | | [react/style-prop-object](docs/rules/style-prop-object.md) | Enforce style prop value is an object | | | | [react/void-dom-elements-no-children](docs/rules/void-dom-elements-no-children.md) | Prevent passing of children to void DOM elements (e.g. `
`). | -## JSX-specific rules +## Stylistic Issues - + | ✔ | 🔧 | Rule | Description | | :---: | :---: | :--- | :--- | -| | 🔧 | [react/jsx-boolean-value](docs/rules/jsx-boolean-value.md) | Enforce boolean attributes notation in JSX | | | | [react/jsx-child-element-spacing](docs/rules/jsx-child-element-spacing.md) | Ensures inline tags are not rendered without spaces between them | | | 🔧 | [react/jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md) | Validate closing bracket location in JSX | | | 🔧 | [react/jsx-closing-tag-location](docs/rules/jsx-closing-tag-location.md) | Validate closing tag location for multiline JSX | @@ -194,36 +216,23 @@ Enable the rules that you would like to use. | | 🔧 | [react/jsx-curly-newline](docs/rules/jsx-curly-newline.md) | Enforce consistent line breaks inside jsx curly | | | 🔧 | [react/jsx-curly-spacing](docs/rules/jsx-curly-spacing.md) | Enforce or disallow spaces inside of curly braces in JSX attributes | | | 🔧 | [react/jsx-equals-spacing](docs/rules/jsx-equals-spacing.md) | Disallow or enforce spaces around equal signs in JSX attributes | -| | | [react/jsx-filename-extension](docs/rules/jsx-filename-extension.md) | Restrict file extensions that may contain JSX | | | 🔧 | [react/jsx-first-prop-new-line](docs/rules/jsx-first-prop-new-line.md) | Ensure proper position of the first property in JSX | -| | 🔧 | [react/jsx-fragments](docs/rules/jsx-fragments.md) | Enforce shorthand or standard form for React fragments | -| | | [react/jsx-handler-names](docs/rules/jsx-handler-names.md) | Enforce event handler naming conventions in JSX | | | 🔧 | [react/jsx-indent](docs/rules/jsx-indent.md) | Validate JSX indentation | | | 🔧 | [react/jsx-indent-props](docs/rules/jsx-indent-props.md) | Validate props indentation in JSX | -| ✔ | | [react/jsx-key](docs/rules/jsx-key.md) | Report missing `key` props in iterators/collection literals | -| | | [react/jsx-max-depth](docs/rules/jsx-max-depth.md) | Validate JSX maximum depth | | | 🔧 | [react/jsx-max-props-per-line](docs/rules/jsx-max-props-per-line.md) | Limit maximum of props on a single line in JSX | | | 🔧 | [react/jsx-newline](docs/rules/jsx-newline.md) | Require or prevent a new line after jsx elements and expressions. | -| | | [react/jsx-no-bind](docs/rules/jsx-no-bind.md) | Prevents usage of Function.prototype.bind and arrow functions in React component props | -| ✔ | | [react/jsx-no-comment-textnodes](docs/rules/jsx-no-comment-textnodes.md) | Comments inside children section of tag should be placed inside braces | -| | | [react/jsx-no-constructed-context-values](docs/rules/jsx-no-constructed-context-values.md) | Prevents JSX context provider values from taking values that will cause needless rerenders. | -| ✔ | | [react/jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md) | Enforce no duplicate props | | | | [react/jsx-no-literals](docs/rules/jsx-no-literals.md) | Prevent using string literals in React component definition | -| | | [react/jsx-no-script-url](docs/rules/jsx-no-script-url.md) | Forbid `javascript:` URLs | -| ✔ | 🔧 | [react/jsx-no-target-blank](docs/rules/jsx-no-target-blank.md) | Forbid `target="_blank"` attribute without `rel="noreferrer"` | -| ✔ | | [react/jsx-no-undef](docs/rules/jsx-no-undef.md) | Disallow undeclared variables in JSX | -| | 🔧 | [react/jsx-no-useless-fragment](docs/rules/jsx-no-useless-fragment.md) | Disallow unnecessary fragments | | | 🔧 | [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md) | Limit to one expression per line in JSX | -| | | [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md) | Enforce PascalCase for user-defined JSX components | | | 🔧 | [react/jsx-props-no-multi-spaces](docs/rules/jsx-props-no-multi-spaces.md) | Disallow multiple spaces between inline JSX props | -| | | [react/jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md) | Prevent JSX prop spreading | | | | [react/jsx-sort-default-props](docs/rules/jsx-sort-default-props.md) | Enforce default props 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) | Validate spacing before closing bracket in JSX | | | 🔧 | [react/jsx-tag-spacing](docs/rules/jsx-tag-spacing.md) | Validate whitespace in and around the JSX opening and closing brackets | -| ✔ | | [react/jsx-uses-react](docs/rules/jsx-uses-react.md) | Prevent React to be marked as unused | -| ✔ | | [react/jsx-uses-vars](docs/rules/jsx-uses-vars.md) | Prevent variables used in JSX to be marked as unused | | | 🔧 | [react/jsx-wrap-multilines](docs/rules/jsx-wrap-multilines.md) | Prevent missing parentheses around multilines JSX | +| | 🔧 | [react/self-closing-comp](docs/rules/self-closing-comp.md) | Prevent extra closing tags for components without children | +| | | [react/sort-comp](docs/rules/sort-comp.md) | Enforce component methods order | +| | | [react/sort-prop-types](docs/rules/sort-prop-types.md) | Enforce propTypes declarations alphabetical sorting | +| | | [react/static-property-placement](docs/rules/static-property-placement.md) | Defines where React component static properties should be positioned. | ## Other useful plugins diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index 5e0a420b7a..b171a0f4aa 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -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'), diff --git a/lib/rules/button-has-type.js b/lib/rules/button-has-type.js index add42d69ca..bbeaa31e43 100644 --- a/lib/rules/button-has-type.js +++ b/lib/rules/button-has-type.js @@ -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'), }, diff --git a/lib/rules/destructuring-assignment.js b/lib/rules/destructuring-assignment.js index 8850df0d3d..1b022402ee 100644 --- a/lib/rules/destructuring-assignment.js +++ b/lib/rules/destructuring-assignment.js @@ -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'), }, diff --git a/lib/rules/function-component-definition.js b/lib/rules/function-component-definition.js index 8f20e63366..6b5b6d512d 100644 --- a/lib/rules/function-component-definition.js +++ b/lib/rules/function-component-definition.js @@ -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'), }, diff --git a/lib/rules/jsx-boolean-value.js b/lib/rules/jsx-boolean-value.js index d68b1ebdf6..42c633cf62 100644 --- a/lib/rules/jsx-boolean-value.js +++ b/lib/rules/jsx-boolean-value.js @@ -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'), }, diff --git a/lib/rules/jsx-filename-extension.js b/lib/rules/jsx-filename-extension.js index fee466f152..76dd7fae20 100644 --- a/lib/rules/jsx-filename-extension.js +++ b/lib/rules/jsx-filename-extension.js @@ -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'), }, diff --git a/lib/rules/jsx-fragments.js b/lib/rules/jsx-fragments.js index 38b4dd8b4b..ae0ae23264 100644 --- a/lib/rules/jsx-fragments.js +++ b/lib/rules/jsx-fragments.js @@ -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'), }, diff --git a/lib/rules/jsx-handler-names.js b/lib/rules/jsx-handler-names.js index e82db76474..4ad4e1cfc6 100644 --- a/lib/rules/jsx-handler-names.js +++ b/lib/rules/jsx-handler-names.js @@ -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'), }, diff --git a/lib/rules/jsx-max-depth.js b/lib/rules/jsx-max-depth.js index b4554c28d3..0869038b9b 100644 --- a/lib/rules/jsx-max-depth.js +++ b/lib/rules/jsx-max-depth.js @@ -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'), }, diff --git a/lib/rules/jsx-no-useless-fragment.js b/lib/rules/jsx-no-useless-fragment.js index ac197e9da9..a5594c9163 100644 --- a/lib/rules/jsx-no-useless-fragment.js +++ b/lib/rules/jsx-no-useless-fragment.js @@ -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'), }, diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js index 901294fa52..b37aad9638 100644 --- a/lib/rules/jsx-pascal-case.js +++ b/lib/rules/jsx-pascal-case.js @@ -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'), }, diff --git a/lib/rules/no-invalid-html-attribute.js b/lib/rules/no-invalid-html-attribute.js index 274f2586da..a7b2399f15 100644 --- a/lib/rules/no-invalid-html-attribute.js +++ b/lib/rules/no-invalid-html-attribute.js @@ -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'), }, diff --git a/lib/rules/no-multi-comp.js b/lib/rules/no-multi-comp.js index 4900063f1f..ed8c132b6b 100644 --- a/lib/rules/no-multi-comp.js +++ b/lib/rules/no-multi-comp.js @@ -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'), }, diff --git a/lib/rules/no-set-state.js b/lib/rules/no-set-state.js index 444840d5e6..d874c7672a 100644 --- a/lib/rules/no-set-state.js +++ b/lib/rules/no-set-state.js @@ -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'), }, diff --git a/lib/rules/no-typos.js b/lib/rules/no-typos.js index 76783729ae..10112babc9 100644 --- a/lib/rules/no-typos.js +++ b/lib/rules/no-typos.js @@ -31,7 +31,7 @@ module.exports = { meta: { docs: { description: 'Prevent common typos', - category: 'Stylistic Issues', + category: 'Best Practices', recommended: false, url: docsUrl('no-typos'), }, diff --git a/lib/rules/no-unstable-nested-components.js b/lib/rules/no-unstable-nested-components.js index ca4ddff560..78514a111b 100644 --- a/lib/rules/no-unstable-nested-components.js +++ b/lib/rules/no-unstable-nested-components.js @@ -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'), }, diff --git a/lib/rules/prefer-es6-class.js b/lib/rules/prefer-es6-class.js index 01ac32ffdb..cfc1ea7873 100644 --- a/lib/rules/prefer-es6-class.js +++ b/lib/rules/prefer-es6-class.js @@ -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'), }, diff --git a/lib/rules/prefer-exact-props.js b/lib/rules/prefer-exact-props.js index 037fa29914..0a684b6e53 100644 --- a/lib/rules/prefer-exact-props.js +++ b/lib/rules/prefer-exact-props.js @@ -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'), }, diff --git a/lib/rules/prefer-read-only-props.js b/lib/rules/prefer-read-only-props.js index f1eb3c3d7c..878e94304e 100644 --- a/lib/rules/prefer-read-only-props.js +++ b/lib/rules/prefer-read-only-props.js @@ -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'), }, diff --git a/lib/rules/prefer-stateless-function.js b/lib/rules/prefer-stateless-function.js index 3ade763a4d..f300a582f0 100644 --- a/lib/rules/prefer-stateless-function.js +++ b/lib/rules/prefer-stateless-function.js @@ -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'), }, diff --git a/lib/rules/state-in-constructor.js b/lib/rules/state-in-constructor.js index a7c543d308..88c61d2abd 100644 --- a/lib/rules/state-in-constructor.js +++ b/lib/rules/state-in-constructor.js @@ -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'), }, diff --git a/markdown.config.js b/markdown.config.js index 2d23dd1931..ad2caa57f7 100644 --- a/markdown.config.js +++ b/markdown.config.js @@ -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'; @@ -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!');