From d2676bc92dfd0ac935922e8bc9baa9b9a4e7ee02 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Mon, 20 Apr 2015 18:57:47 +0300 Subject: [PATCH] Add docs for jsx-sort-prop-types rule. --- README.md | 3 +- docs/rules/jsx-sort-prop-types.md | 91 +++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 docs/rules/jsx-sort-prop-types.md diff --git a/README.md b/README.md index 667d04427e..b3d2881110 100755 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Finally, enable all of the rules that you would like to use. "react/jsx-quotes": 1, "react/jsx-no-undef": 1, "react/jsx-sort-props": 1, + "react/jsx-sort-prop-types": 1, "react/jsx-uses-react": 1, "react/jsx-uses-vars": 1, "react/no-did-mount-set-state": 1, @@ -68,6 +69,7 @@ Finally, enable all of the rules that you would like to use. * [jsx-quotes](docs/rules/jsx-quotes.md): Enforce quote style for JSX attributes * [jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX * [jsx-sort-props](docs/rules/jsx-sort-props.md): Enforce props alphabetical sorting +* [jsx-sort-prop-types](docs/rules/jsx-sort-prop-types.md): Enforce propTypes declarations alphabetical sorting * [jsx-uses-react](docs/rules/jsx-uses-react.md): Prevent React to be incorrectly marked as unused * [jsx-uses-vars](docs/rules/jsx-uses-vars.md): Prevent variables used in JSX to be incorrectly marked as unused * [no-did-mount-set-state](docs/rules/no-did-mount-set-state.md): Prevent usage of setState in componentDidMount @@ -111,4 +113,3 @@ ESLint-plugin-React is licensed under the [MIT License](http://www.opensource.or [status-url]: https://github.com/yannickcr/eslint-plugin-react/pulse [status-image]: http://img.shields.io/badge/status-maintained-brightgreen.svg?style=flat-square - diff --git a/docs/rules/jsx-sort-prop-types.md b/docs/rules/jsx-sort-prop-types.md new file mode 100644 index 0000000000..f1f10681f9 --- /dev/null +++ b/docs/rules/jsx-sort-prop-types.md @@ -0,0 +1,91 @@ +# Enforce propTypes declarations alphabetical sorting (jsx-sort-prop-types) + +Some developers prefer to sort propsTypes declarations alphabetically to be able to find necessary declaration easier at the later time. Others feel that it adds complexity and becomes burden to maintain. + +## Rule Details + +This rule checks all JSX components and verifies that all propsTypes declarations are sorted alphabetically. +The default configuration of the rule is case-sensitive. +This rule is off by default. + +The following patterns are considered warnings: + +```js +var Component = React.createClass({ + propTypes: { + z: React.PropTypes.number, + a: React.PropTypes.any, + b: React.PropTypes.string + }, +... +}); + +class Component extends React.Component { + ... +} +Component.propTypes = { + z: React.PropTypes.number, + a: React.PropTypes.any, + b: React.PropTypes.string +}; + +class Component extends React.Component { + static propTypes = { + z: React.PropTypes.any, + y: React.PropTypes.any, + a: React.PropTypes.any + } + render() { + return
; + } +} +``` + +The following patterns are considered okay and do not cause warnings: + +```js +var Component = React.createClass({ + propTypes: { + a: React.PropTypes.number, + b: React.PropTypes.any, + c: React.PropTypes.string + }, +... +}); + +class Component extends React.Component { + ... +} +Component.propTypes = { + a: React.PropTypes.string, + b: React.PropTypes.any, + c: React.PropTypes.string +}; + +class Component extends React.Component { + static propTypes = { + a: React.PropTypes.any, + b: React.PropTypes.any, + c: React.PropTypes.any + } + render() { + return
; + } +} +``` + +## Rule Options + +```js +... +"jsx-sort-prop-types": [, { "ignoreCase": }] +... +``` + +### `ignoreCase` + +When `true` the rule ignores the case-sensitivity of the declarations order. + +## When not to use + +This rule is a formatting preference and not following it won't negatively affect the quality of your code. If alphabetizing props declarations isn't a part of your coding standards, then you can leave this rule off.