@@ -34,6 +34,13 @@ module.exports = {
34
34
// This rule enforces the consistent use of either double or single quotes in JSX attributes.
35
35
'jsx-quotes' : [ 'warn' , 'prefer-double' ] ,
36
36
37
+ // Prevent usage of button elements without an explicit type attribute
38
+ // The default value of type attribute for button HTML element is "submit" which is often not
39
+ // the desired behavior and may lead to unexpected page reloads. This rules enforces an explicit
40
+ // type attribute for all the button elements and checks that its value is valid per spec
41
+ // (button, submit, reset).
42
+ 'react/button-has-type' : 'warn' ,
43
+
37
44
// Enforce boolean attributes notation in JSX
38
45
// In JSX when using a boolean attribute you can set the attribute value to true or omit the
39
46
// value. This rule will enforce one or the other to keep consistency in your code.
@@ -111,6 +118,12 @@ module.exports = {
111
118
// results in in unnecessary renders.
112
119
'react/no-array-index-key' : 'warn' ,
113
120
121
+ // Prevent using this.state within a this.setState
122
+ // This rule should prevent usage of this.state inside setState calls. Such usage of this.state
123
+ // might result in errors when two state calls are called in batch and thus referencing old
124
+ // state and not the current state.
125
+ 'react/no-access-state-in-setstate' : 'error' ,
126
+
114
127
// Prevent usage of deprecated methods
115
128
'react/no-deprecated' : 'warn' ,
116
129
@@ -168,6 +181,13 @@ module.exports = {
168
181
// by setting a property on the this object in the reference callback is preferred.
169
182
'react/no-string-refs' : 'error' ,
170
183
184
+ // Prevent this from being used in stateless functional components
185
+ // When using a stateless functional component (SFC), props/context aren't accessed in the same
186
+ // way as a class component or the create-react-class format. Both props and context are passed
187
+ // as separate arguments to the component instead. Also, as the name suggests, a stateless
188
+ // component does not have state on this.state.
189
+ 'react/no-this-in-sfc' : 'error' ,
190
+
171
191
// Prevents common typos
172
192
// This rule checks whether the declared static class properties and lifecycle methods related
173
193
// to React components do not contain any typos.
@@ -179,6 +199,13 @@ module.exports = {
179
199
// HTML.
180
200
'react/no-unknown-property' : 'error' ,
181
201
202
+
203
+ // Prevent usage of UNSAFE_ methods
204
+ // Certain legacy lifecycle methods are unsafe for use in async React applications and cause
205
+ // warnings in strict mode. These also happen to be the lifecycles that cause the most confusion
206
+ // within the React community.
207
+ 'react/no-unsafe' : 'error' ,
208
+
182
209
// Prevent definitions of unused prop types
183
210
// Warns you if you have defined a prop type but it is never being used anywhere.
184
211
'react/no-unused-prop-types' : [ 'error' , {
@@ -188,7 +215,7 @@ module.exports = {
188
215
} ] ,
189
216
190
217
// Prevent definition of unused state fields
191
- 'react/no-unused-state' : [ 'warn' ] ,
218
+ 'react/no-unused-state' : 'warn' ,
192
219
193
220
// Enforce ES6 class for React Components
194
221
'react/prefer-es6-class' : [ 'error' , 'always' ] ,
@@ -215,7 +242,9 @@ module.exports = {
215
242
// Enforce a `defaultProps` definition for every prop that is not a required prop
216
243
// This rule aims to ensure that any non-required PropType declaration of a component has a
217
244
// corresponding `defaultProps` value.
218
- 'react/require-default-props' : 'error' ,
245
+ 'react/require-default-props' : [ 'error' , {
246
+ forbidDefaultForRequired : true ,
247
+ } ] ,
219
248
220
249
// Enforce ES5 or ES6 class for returning value in render function
221
250
// When writing the render method in a component it is easy to forget to return the JSX content.
0 commit comments