Skip to content

Commit 182b045

Browse files
ybiquitousljharb
authored andcommitted
[Docs] use markdown-magic to automatically sort all rules alphabetically
To make it easier to find rules. This adds a script to auto-generate the list of rules and embeds special tags to README. Usage: $ npm run generate-list-of-rules Check whether the auto-generated changes are committed: $ npm run generate-list-of-rules:check Use `markdown-magic` package to transform README https://www.npmjs.com/package/markdown-magic
1 parent 45b9d32 commit 182b045

File tree

5 files changed

+94
-57
lines changed

5 files changed

+94
-57
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ before_script:
1414
- 'if [ -n "${ESLINT-}" ]; then npm install --no-save "eslint@${ESLINT}" ; fi'
1515
script:
1616
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
17-
- 'if [ -z "${PRETEST-}" ] && [ -n "${TEST-}" ]; then npm run unit-test ; fi'
17+
- 'if [ -n "${TEST-}" ]; then npm run unit-test ; fi'
18+
- 'if [ -n "${README-}" ]; then npm run generate-list-of-rules:check ; fi'
1819
env:
1920
global:
2021
- TEST=true
@@ -29,6 +30,8 @@ matrix:
2930
include:
3031
- node_js: 'lts/*'
3132
env: PRETEST=true
33+
- node_js: 'lts/*'
34+
env: README=true
3235
exclude:
3336
- node_js: '4'
3437
env: ESLINT=5

README.md

+60-54
Original file line numberDiff line numberDiff line change
@@ -97,94 +97,100 @@ Enable the rules that you would like to use.
9797

9898
# List of supported rules
9999

100+
<!-- AUTO-GENERATED-CONTENT:START (BASIC_RULES) -->
100101
* [react/boolean-prop-naming](docs/rules/boolean-prop-naming.md): Enforces consistent naming for boolean props
101102
* [react/button-has-type](docs/rules/button-has-type.md): Forbid "button" element without an explicit "type" attribute
102-
* [react/default-props-match-prop-types](docs/rules/default-props-match-prop-types.md): Prevent extraneous defaultProps on components
103-
* [react/destructuring-assignment](docs/rules/destructuring-assignment.md): Rule enforces consistent usage of destructuring assignment in component
104-
* [react/display-name](docs/rules/display-name.md): Prevent missing `displayName` in a React component definition
105-
* [react/forbid-component-props](docs/rules/forbid-component-props.md): Forbid certain props on Components
103+
* [react/default-props-match-prop-types](docs/rules/default-props-match-prop-types.md): Enforce all defaultProps are defined and not "required" in propTypes.
104+
* [react/destructuring-assignment](docs/rules/destructuring-assignment.md): Enforce consistent usage of destructuring assignment of props, state, and context
105+
* [react/display-name](docs/rules/display-name.md): Prevent missing displayName in a React component definition
106+
* [react/forbid-component-props](docs/rules/forbid-component-props.md): Forbid certain props on components
106107
* [react/forbid-dom-props](docs/rules/forbid-dom-props.md): Forbid certain props on DOM Nodes
107108
* [react/forbid-elements](docs/rules/forbid-elements.md): Forbid certain elements
109+
* [react/forbid-foreign-prop-types](docs/rules/forbid-foreign-prop-types.md): Forbid using another component's propTypes
108110
* [react/forbid-prop-types](docs/rules/forbid-prop-types.md): Forbid certain propTypes
109-
* [react/forbid-foreign-prop-types](docs/rules/forbid-foreign-prop-types.md): Forbid foreign propTypes
110-
* [react/no-access-state-in-setstate](docs/rules/no-access-state-in-setstate.md): Prevent using this.state inside this.setState
111-
* [react/no-array-index-key](docs/rules/no-array-index-key.md): Prevent using Array index in `key` props
112-
* [react/no-children-prop](docs/rules/no-children-prop.md): Prevent passing children as props
113-
* [react/no-danger](docs/rules/no-danger.md): Prevent usage of dangerous JSX properties
114-
* [react/no-danger-with-children](docs/rules/no-danger-with-children.md): Prevent problem with children and props.dangerouslySetInnerHTML
115-
* [react/no-deprecated](docs/rules/no-deprecated.md): Prevent usage of deprecated methods, including component lifecycle methods
116-
* [react/no-did-mount-set-state](docs/rules/no-did-mount-set-state.md): Prevent usage of `setState` in `componentDidMount`
117-
* [react/no-did-update-set-state](docs/rules/no-did-update-set-state.md): Prevent usage of `setState` in `componentDidUpdate`
118-
* [react/no-direct-mutation-state](docs/rules/no-direct-mutation-state.md): Prevent direct mutation of `this.state`
119-
* [react/no-find-dom-node](docs/rules/no-find-dom-node.md): Prevent usage of `findDOMNode`
120-
* [react/no-is-mounted](docs/rules/no-is-mounted.md): Prevent usage of `isMounted`
111+
* [react/function-component-definition](docs/rules/function-component-definition.md): Standardize the way function component get defined (fixable)
112+
* [react/no-access-state-in-setstate](docs/rules/no-access-state-in-setstate.md): Reports when this.state is accessed within setState
113+
* [react/no-adjacent-inline-elements](docs/rules/no-adjacent-inline-elements.md): Prevent adjacent inline elements not separated by whitespace.
114+
* [react/no-array-index-key](docs/rules/no-array-index-key.md): Prevent usage of Array index in keys
115+
* [react/no-children-prop](docs/rules/no-children-prop.md): Prevent passing of children as props.
116+
* [react/no-danger](docs/rules/no-danger.md): Prevent usage of dangerous JSX props
117+
* [react/no-danger-with-children](docs/rules/no-danger-with-children.md): Report when a DOM element is using both children and dangerouslySetInnerHTML
118+
* [react/no-deprecated](docs/rules/no-deprecated.md): Prevent usage of deprecated methods
119+
* [react/no-did-mount-set-state](docs/rules/no-did-mount-set-state.md): Prevent usage of setState in componentDidMount
120+
* [react/no-did-update-set-state](docs/rules/no-did-update-set-state.md): Prevent usage of setState in componentDidUpdate
121+
* [react/no-direct-mutation-state](docs/rules/no-direct-mutation-state.md): Prevent direct mutation of this.state
122+
* [react/no-find-dom-node](docs/rules/no-find-dom-node.md): Prevent usage of findDOMNode
123+
* [react/no-is-mounted](docs/rules/no-is-mounted.md): Prevent usage of isMounted
121124
* [react/no-multi-comp](docs/rules/no-multi-comp.md): Prevent multiple component definition per file
122-
* [react/no-redundant-should-component-update](docs/rules/no-redundant-should-component-update.md): Prevent usage of `shouldComponentUpdate` when extending React.PureComponent
123-
* [react/no-render-return-value](docs/rules/no-render-return-value.md): Prevent usage of the return value of `React.render`
124-
* [react/no-set-state](docs/rules/no-set-state.md): Prevent usage of `setState`
125-
* [react/no-typos](docs/rules/no-typos.md): Prevent common casing typos
126-
* [react/no-string-refs](docs/rules/no-string-refs.md): Prevent using string references in `ref` attribute.
127-
* [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md): Prevent using `this` in stateless functional components
128-
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Prevent invalid characters from appearing in markup
125+
* [react/no-redundant-should-component-update](docs/rules/no-redundant-should-component-update.md): Flag shouldComponentUpdate when extending PureComponent
126+
* [react/no-render-return-value](docs/rules/no-render-return-value.md): Prevent usage of the return value of React.render
127+
* [react/no-set-state](docs/rules/no-set-state.md): Prevent usage of setState
128+
* [react/no-string-refs](docs/rules/no-string-refs.md): Prevent string definitions for references and prevent referencing this.refs
129+
* [react/no-this-in-sfc](docs/rules/no-this-in-sfc.md): Report "this" being used in stateless components
130+
* [react/no-typos](docs/rules/no-typos.md): Prevent common typos
131+
* [react/no-unescaped-entities](docs/rules/no-unescaped-entities.md): Detect unescaped HTML entities, which might represent malformed tags
129132
* [react/no-unknown-property](docs/rules/no-unknown-property.md): Prevent usage of unknown DOM property (fixable)
130133
* [react/no-unsafe](docs/rules/no-unsafe.md): Prevent usage of unsafe lifecycle methods
131134
* [react/no-unused-prop-types](docs/rules/no-unused-prop-types.md): Prevent definitions of unused prop types
132-
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definitions of unused state properties
133-
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of `setState` in `componentWillUpdate`
135+
* [react/no-unused-state](docs/rules/no-unused-state.md): Prevent definition of unused state fields
136+
* [react/no-will-update-set-state](docs/rules/no-will-update-set-state.md): Prevent usage of setState in componentWillUpdate
134137
* [react/prefer-es6-class](docs/rules/prefer-es6-class.md): Enforce ES5 or ES6 class for React Components
135-
* [react/prefer-read-only-props](docs/rules/prefer-read-only-props.md): Enforce that props are read-only
136-
* [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless React Components to be written as a pure function
138+
* [react/prefer-read-only-props](docs/rules/prefer-read-only-props.md): Require read-only props. (fixable)
139+
* [react/prefer-stateless-function](docs/rules/prefer-stateless-function.md): Enforce stateless components to be written as a pure function
137140
* [react/prop-types](docs/rules/prop-types.md): Prevent missing props validation in a React component definition
138-
* [react/react-in-jsx-scope](docs/rules/react-in-jsx-scope.md): Prevent missing `React` when using JSX
139-
* [react/require-default-props](docs/rules/require-default-props.md): Enforce a defaultProps definition for every prop that is not a required prop
140-
* [react/require-optimization](docs/rules/require-optimization.md): Enforce React components to have a `shouldComponentUpdate` method
141+
* [react/react-in-jsx-scope](docs/rules/react-in-jsx-scope.md): Prevent missing React when using JSX
142+
* [react/require-default-props](docs/rules/require-default-props.md): Enforce a defaultProps definition for every prop that is not a required prop.
143+
* [react/require-optimization](docs/rules/require-optimization.md): Enforce React components to have a shouldComponentUpdate method
141144
* [react/require-render-return](docs/rules/require-render-return.md): Enforce ES5 or ES6 class for returning value in render function
142145
* [react/self-closing-comp](docs/rules/self-closing-comp.md): Prevent extra closing tags for components without children (fixable)
143-
* [react/sort-comp](docs/rules/sort-comp.md): Enforce component methods order (fixable)
146+
* [react/sort-comp](docs/rules/sort-comp.md): Enforce component methods order
144147
* [react/sort-prop-types](docs/rules/sort-prop-types.md): Enforce propTypes declarations alphabetical sorting
145-
* [react/state-in-constructor](docs/rules/state-in-constructor.md): Enforce the state initialization style to be either in a constructor or with a class property
146-
* [react/static-property-placement](docs/rules/static-property-placement.md): Enforces where React component static properties should be positioned.
147-
* [react/style-prop-object](docs/rules/style-prop-object.md): Enforce style prop value being an object
148-
* [react/void-dom-elements-no-children](docs/rules/void-dom-elements-no-children.md): Prevent void DOM elements (e.g. `<img />`, `<br />`) from receiving children
148+
* [react/state-in-constructor](docs/rules/state-in-constructor.md): State initialization in an ES6 class component should be in a constructor
149+
* [react/static-property-placement](docs/rules/static-property-placement.md): Defines where React component static properties should be positioned.
150+
* [react/style-prop-object](docs/rules/style-prop-object.md): Enforce style prop value is an object
151+
* [react/void-dom-elements-no-children](docs/rules/void-dom-elements-no-children.md): Prevent passing of children to void DOM elements (e.g. `<br />`).
152+
<!-- AUTO-GENERATED-CONTENT:END -->
149153

150154
## JSX-specific rules
151155

156+
<!-- AUTO-GENERATED-CONTENT:START (JSX_RULES) -->
152157
* [react/jsx-boolean-value](docs/rules/jsx-boolean-value.md): Enforce boolean attributes notation in JSX (fixable)
153-
* [react/jsx-child-element-spacing](docs/rules/jsx-child-element-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes and expressions.
158+
* [react/jsx-child-element-spacing](docs/rules/jsx-child-element-spacing.md): Ensures inline tags are not rendered without spaces between them
154159
* [react/jsx-closing-bracket-location](docs/rules/jsx-closing-bracket-location.md): Validate closing bracket location in JSX (fixable)
155-
* [react/jsx-closing-tag-location](docs/rules/jsx-closing-tag-location.md): Validate closing tag location in JSX (fixable)
156-
* [react/jsx-curly-newline](docs/rules/jsx-curly-newline.md): Enforce or disallow newlines inside of curly braces in JSX attributes and expressions (fixable)
157-
* [react/jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes and expressions (fixable)
158-
* [react/jsx-equals-spacing](docs/rules/jsx-equals-spacing.md): Enforce or disallow spaces around equal signs in JSX attributes (fixable)
160+
* [react/jsx-closing-tag-location](docs/rules/jsx-closing-tag-location.md): Validate closing tag location for multiline JSX (fixable)
161+
* [react/jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md): Disallow unnecessary JSX expressions when literals alone are sufficient or enfore JSX expressions on literals in JSX children or attributes (fixable)
162+
* [react/jsx-curly-newline](docs/rules/jsx-curly-newline.md): enforce consistent line breaks inside jsx curly (fixable)
163+
* [react/jsx-curly-spacing](docs/rules/jsx-curly-spacing.md): Enforce or disallow spaces inside of curly braces in JSX attributes (fixable)
164+
* [react/jsx-equals-spacing](docs/rules/jsx-equals-spacing.md): Disallow or enforce spaces around equal signs in JSX attributes (fixable)
159165
* [react/jsx-filename-extension](docs/rules/jsx-filename-extension.md): Restrict file extensions that may contain JSX
160-
* [react/jsx-first-prop-new-line](docs/rules/jsx-first-prop-new-line.md): Enforce position of the first prop in JSX (fixable)
166+
* [react/jsx-first-prop-new-line](docs/rules/jsx-first-prop-new-line.md): Ensure proper position of the first property in JSX (fixable)
167+
* [react/jsx-fragments](docs/rules/jsx-fragments.md): Enforce shorthand or standard form for React fragments (fixable)
161168
* [react/jsx-handler-names](docs/rules/jsx-handler-names.md): Enforce event handler naming conventions in JSX
162169
* [react/jsx-indent](docs/rules/jsx-indent.md): Validate JSX indentation (fixable)
163170
* [react/jsx-indent-props](docs/rules/jsx-indent-props.md): Validate props indentation in JSX (fixable)
164-
* [react/jsx-key](docs/rules/jsx-key.md): Validate JSX has key prop when in array or iterator
171+
* [react/jsx-key](docs/rules/jsx-key.md): Report missing `key` props in iterators/collection literals
165172
* [react/jsx-max-depth](docs/rules/jsx-max-depth.md): Validate JSX maximum depth
166173
* [react/jsx-max-props-per-line](docs/rules/jsx-max-props-per-line.md): Limit maximum of props on a single line in JSX (fixable)
167-
* [react/jsx-no-bind](docs/rules/jsx-no-bind.md): Prevent usage of `.bind()` and arrow functions in JSX props
168-
* [react/jsx-no-comment-textnodes](docs/rules/jsx-no-comment-textnodes.md): Prevent comments from being inserted as text nodes
169-
* [react/jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md): Prevent duplicate props in JSX
170-
* [react/jsx-no-literals](docs/rules/jsx-no-literals.md): Prevent usage of unwrapped JSX strings
171-
* [react/jsx-no-script-url](docs/rules/jsx-no-script-url.md): Prevent usage of `javascript:` URLs
172-
* [react/jsx-no-target-blank](docs/rules/jsx-no-target-blank.md): Prevent usage of unsafe `target='_blank'`
174+
* [react/jsx-no-bind](docs/rules/jsx-no-bind.md): Prevents usage of Function.prototype.bind and arrow functions in React component props
175+
* [react/jsx-no-comment-textnodes](docs/rules/jsx-no-comment-textnodes.md): Comments inside children section of tag should be placed inside braces
176+
* [react/jsx-no-duplicate-props](docs/rules/jsx-no-duplicate-props.md): Enforce no duplicate props
177+
* [react/jsx-no-literals](docs/rules/jsx-no-literals.md): Prevent using string literals in React component definition
178+
* [react/jsx-no-script-url](docs/rules/jsx-no-script-url.md): Forbid `javascript:` URLs
179+
* [react/jsx-no-target-blank](docs/rules/jsx-no-target-blank.md): Forbid target="_blank" attribute without rel="noopener noreferrer"
173180
* [react/jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX
174181
* [react/jsx-no-useless-fragment](docs/rules/jsx-no-useless-fragment.md): Disallow unnecessary fragments (fixable)
175-
* [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md): Limit to one expression per line in JSX
176-
* [react/jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md): Enforce curly braces or disallow unnecessary curly braces in JSX
177-
* [react/jsx-fragments](docs/rules/jsx-fragments.md): Enforce shorthand or standard form for React fragments
182+
* [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md): Limit to one expression per line in JSX (fixable)
178183
* [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md): Enforce PascalCase for user-defined JSX components
179184
* [react/jsx-props-no-multi-spaces](docs/rules/jsx-props-no-multi-spaces.md): Disallow multiple spaces between inline JSX props (fixable)
180-
* [react/jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md): Disallow JSX props spreading
185+
* [react/jsx-props-no-spreading](docs/rules/jsx-props-no-spreading.md): Prevent JSX prop spreading
181186
* [react/jsx-sort-default-props](docs/rules/jsx-sort-default-props.md): Enforce default props alphabetical sorting
182187
* [react/jsx-sort-props](docs/rules/jsx-sort-props.md): Enforce props alphabetical sorting (fixable)
183188
* [react/jsx-space-before-closing](docs/rules/jsx-space-before-closing.md): Validate spacing before closing bracket in JSX (fixable)
184189
* [react/jsx-tag-spacing](docs/rules/jsx-tag-spacing.md): Validate whitespace in and around the JSX opening and closing brackets (fixable)
185-
* [react/jsx-uses-react](docs/rules/jsx-uses-react.md): Prevent React to be incorrectly marked as unused
186-
* [react/jsx-uses-vars](docs/rules/jsx-uses-vars.md): Prevent variables used in JSX to be incorrectly marked as unused
190+
* [react/jsx-uses-react](docs/rules/jsx-uses-react.md): Prevent React to be marked as unused
191+
* [react/jsx-uses-vars](docs/rules/jsx-uses-vars.md): Prevent variables used in JSX to be marked as unused
187192
* [react/jsx-wrap-multilines](docs/rules/jsx-wrap-multilines.md): Prevent missing parentheses around multilines JSX (fixable)
193+
<!-- AUTO-GENERATED-CONTENT:END -->
188194

189195
## Other useful plugins
190196

lib/rules/void-dom-elements-no-children.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function errorMessage(elementName) {
5151
module.exports = {
5252
meta: {
5353
docs: {
54-
description: 'Prevent passing of children to void DOM elements (e.g. <br />).',
54+
description: 'Prevent passing of children to void DOM elements (e.g. `<br />`).',
5555
category: 'Best Practices',
5656
recommended: false,
5757
url: docsUrl('void-dom-elements-no-children')

markdown.config.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const {rules} = require('./index');
4+
5+
const ruleListItems = Object.keys(rules)
6+
.sort()
7+
.map((id) => {
8+
const {meta} = rules[id];
9+
const {fixable, docs} = meta;
10+
return `* [react/${id}](docs/rules/${id}.md): ${docs.description}${fixable ? ' (fixable)' : ''}`;
11+
});
12+
13+
const BASIC_RULES = () => ruleListItems.filter(rule => !rule.includes('react/jsx-')).join('\n');
14+
const JSX_RULES = () => ruleListItems.filter(rule => rule.includes('react/jsx-')).join('\n');
15+
16+
module.exports = {
17+
transforms: {
18+
BASIC_RULES,
19+
JSX_RULES
20+
},
21+
callback: () => {
22+
// eslint-disable-next-line no-console
23+
console.log('The auto-generating of rules finished!');
24+
}
25+
};

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"pretest": "npm run lint",
1212
"test": "npm run unit-test",
1313
"type-check": "tsc",
14-
"unit-test": "istanbul cover node_modules/mocha/bin/_mocha tests/lib/**/*.js tests/util/**/*.js tests/index.js"
14+
"unit-test": "istanbul cover node_modules/mocha/bin/_mocha tests/lib/**/*.js tests/util/**/*.js tests/index.js",
15+
"generate-list-of-rules": "md-magic --path README.md",
16+
"generate-list-of-rules:check": "npm run generate-list-of-rules && git diff --exit-code README.md"
1517
},
1618
"files": [
1719
"LICENSE",
@@ -47,6 +49,7 @@
4749
"eslint-plugin-eslint-plugin": "^2.1.0",
4850
"eslint-plugin-import": "^2.18.2",
4951
"istanbul": "^0.4.5",
52+
"markdown-magic": "^1.0.0",
5053
"mocha": "^5.2.0",
5154
"sinon": "^7.5.0",
5255
"typescript": "^3.7.2",

0 commit comments

Comments
 (0)