Skip to content
This repository was archived by the owner on May 16, 2020. It is now read-only.

Commit 3876745

Browse files
feat: add in ESLint rules for the React plugin
1 parent eb35d5d commit 3876745

File tree

3 files changed

+182
-1
lines changed

3 files changed

+182
-1
lines changed

packages/eslint-config-atlauncher/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const configs = [
99
const rules = [
1010
'./rules/base',
1111
'./rules/plugin-filenames',
12-
'./rules/plugin-import'
12+
'./rules/plugin-import',
13+
'./rules/plugin-jsx-a11y',
14+
'./rules/plugin-react'
1315
].map(require.resolve);
1416

1517
module.exports = {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable import/no-commonjs */
2+
3+
module.exports = {
4+
rules: {
5+
}
6+
};
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/* eslint-disable import/no-commonjs */
2+
3+
module.exports = {
4+
settings: {
5+
react: {
6+
version: "15.4.0"
7+
}
8+
},
9+
rules: {
10+
// require setting of `displayName` property on components
11+
'react/display-name': 'error',
12+
13+
// forbids the use of `className` and `style` properties on components, only on root elements (div, span, etc)
14+
'react/forbid-component-props': ['error', {forbid: ['className', 'style']}],
15+
16+
// don't allow the use of any or array PropTypes as they're too vague
17+
'react/forbid-prop-types': ['error', {forbid: ['any', 'array']}],
18+
19+
// don't allow using other components propTypes unless exported out the component
20+
'react/forbid-foreign-prop-types': 'error',
21+
22+
// don't allow using array indexes as key's when looping over arrays for components
23+
'react/no-array-index-key': 'error',
24+
25+
// don't allow children of a component to be passed in as a property, they should be done via JSX nesting
26+
'react/no-children-prop': 'error',
27+
28+
// warn when using `dangerouslySetInnerHTML` as we shouldn't be using it, but sometimes may be necessary
29+
'react/no-danger': 'warn',
30+
31+
// don't allow using `dangerouslySetInnerHTML` as well as children via JSX nesting
32+
'react/no-danger-with-children': 'error',
33+
34+
// don't allow using deprecated methods of React
35+
'react/no-deprecated': 'error',
36+
37+
// don't allow `setState` in `componentDidMount` methods outside of `onMount`
38+
'react/no-did-mount-set-state': 'error',
39+
40+
// don't allow `setState` in `componentDidUpdate` methods outside of `onUpdate`
41+
'react/no-did-update-set-state': 'error',
42+
43+
// don't allow mutating state via `this.state`
44+
'react/no-direct-mutation-state': 'error',
45+
46+
// don't allow use of `findDOMNode`
47+
'react/no-find-dom-node': 'error',
48+
49+
// don't allow use of deprecated `isMounted` function
50+
'react/no-is-mounted': 'error',
51+
52+
// don't allow more than one component per file, even stateless components
53+
'react/no-multi-comp': ['error', {ignoreStateless: false}],
54+
55+
// don't allow using the return value from `ReactDOM.render()`
56+
'react/no-render-return-value': 'error',
57+
58+
// don't allow using string ref attributes
59+
'react/no-string-refs': 'error',
60+
61+
// don't allow the use of unescaped entities in JSX
62+
'react/no-unescaped-entities': 'error',
63+
64+
// enforce the use of camelCase property names
65+
'react/no-unknown-property': 'error',
66+
67+
// don't allow unused PropType's
68+
'react/no-unused-prop-types': 'error',
69+
70+
// requires all components to be written as ES6 classes and not via `React.createClass`
71+
'react/prefer-es6-class': 'error',
72+
73+
// ensures stateless components aren't doing more than they should
74+
'react/prefer-stateless-function': 'error',
75+
76+
// ensures PropType's are written and contain all properties are added into it
77+
'react/prop-types': 'error',
78+
79+
// ensures React has been imported into all files using JSX
80+
'react/react-in-jsx-scope': 'error',
81+
82+
// requires all PropType's that aren't required to have a default defined for it
83+
'react/require-default-props': 'error',
84+
85+
// requires render functions return correctly
86+
'react/require-render-return': 'error',
87+
88+
// requires components with no children to use self closing tags
89+
'react/self-closing-comp': 'error',
90+
91+
// ensures correct ordering of methods in a class component
92+
'react/sort-comp': ['error', {
93+
order: [
94+
'static-methods',
95+
'lifecycle',
96+
'everything-else',
97+
'rendering'
98+
],
99+
groups: {
100+
rendering: [
101+
'/^render.+$/',
102+
'render'
103+
]
104+
}
105+
}],
106+
107+
// require style properties to be defined in a variable
108+
'react/style-prop-object': 'error',
109+
110+
// don't allow self closing DOM elements to have children (img, br, etc)
111+
'react/void-dom-elements-no-children': 'error',
112+
113+
// all boolean attributes must be specified as `<A prop={true} />` rather than just `<A prop />`
114+
'react/jsx-boolean-value': ['error', 'always'],
115+
116+
// ensures any multiline components will have closing tag aligning with the opening tag
117+
'react/jsx-closing-bracket-location': 'error',
118+
119+
// don't allow spaces in between JSX variables like `<A prop={ test } />`
120+
'react/jsx-curly-spacing': ['error', 'never'],
121+
122+
// don't allow spaces around the `=` in JSX variables like `<A prop = {test} />`
123+
'react/jsx-equals-spacing': ['error', 'never'],
124+
125+
// only allow naming components as .js and not .jsx
126+
'react/jsx-filename-extension': ['error', {extensions: ['.js']}],
127+
128+
// require any multiline components to have the first property on a new line
129+
'react/jsx-first-prop-new-line': ['error', 'multiline'],
130+
131+
// ensure all properties use event handlers prefixed with `on` and class methods prefixed with `handle`
132+
'react/jsx-handler-names': ['error', {
133+
eventHandlerPrefix: 'handle',
134+
eventHandlerPropPrefix: 'on'
135+
}],
136+
137+
// ensure all indents in JSX use 4 spaces
138+
'react/jsx-indent': ['error', 4],
139+
140+
// ensure all indents in props to use 4 spaces
141+
'react/jsx-indent-props': ['error', 4],
142+
143+
// require the `key` property to be specified where needed
144+
'react/jsx-key': 'error',
145+
146+
// don't allow the use of HTML comments and enforce JSX comment style
147+
'react/jsx-no-comment-textnodes': 'error',
148+
149+
// don't allow duplicate props
150+
'react/jsx-no-duplicate-props': 'error',
151+
152+
// don't allow `target="_blank"` on links without `rel="noopener noreferrer"`
153+
'react/jsx-no-target-blank': 'error',
154+
155+
// don't allow using undefined components
156+
'react/jsx-no-undef': 'error',
157+
158+
// require all components use PascalCase
159+
'react/jsx-pascal-case': 'error',
160+
161+
// require a space before self closing tags such as `<A prop={prop} />` rather than `<A prop={prop}/>`
162+
'react/jsx-space-before-closing': 'error',
163+
164+
// ensures components that import React don't show it as being unused
165+
'react/jsx-uses-react': 'error',
166+
167+
// ensures imported components don't show up as unused when used in JSX
168+
'react/jsx-uses-vars': 'error',
169+
170+
// ensures multiline JSX is wrapped within parenthesis
171+
'react/jsx-wrap-multilines': 'error'
172+
}
173+
};

0 commit comments

Comments
 (0)