Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.

Commit 947208c

Browse files
feat: upgrade eslint-plugin-react to 7.11
BREAKING CHANGE: adds new `error` level rules.
1 parent b075a02 commit 947208c

File tree

6 files changed

+94
-118
lines changed

6 files changed

+94
-118
lines changed

coding-styles/react.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ module.exports = {
1616
],
1717

1818
rules: {
19+
// Enforce consistent usage of destructuring assignment of props, state, and context
20+
'react/destructuring-assignment': ['warn', {
21+
ignoreClassFields: true,
22+
}],
23+
1924
// Validate closing bracket location in JSX
2025
// This rule checks all JSX multiline elements and verifies the location of the closing bracket.
2126
'react/jsx-closing-bracket-location': ['warn', 'line-aligned'],
@@ -43,6 +48,11 @@ module.exports = {
4348
// Validate props indentation in JSX
4449
'react/jsx-indent-props': ['warn', 2],
4550

51+
// Validate JSX maximum depth
52+
'react/jsx-max-depth': ['warn', {
53+
max: 4,
54+
}],
55+
4656
// Enforce PascalCase for user-defined JSX components
4757
// Enforces coding style that user-defined JSX components are defined and referenced in
4858
// PascalCase.
@@ -51,10 +61,21 @@ module.exports = {
5161
ignore: [],
5262
}],
5363

64+
// Disallow multiple spaces between inline JSX props
65+
// Enforces that there is exactly one space between all attributes and after tag name and the
66+
// first attribute in the same line.
67+
'react/jsx-props-no-multi-spaces': 'warn',
68+
5469
// Validate whitespace in and around the JSX opening and closing brackets
5570
// This rule checks the whitespace inside and surrounding the JSX syntactic elements.
5671
'react/jsx-tag-spacing': 'warn',
5772

73+
// Enforce one JSX element per line
74+
// This option limits every line in JSX to one expression each.
75+
'react/jsx-one-expression-per-line': ['warn', {
76+
allow: 'single-child',
77+
}],
78+
5879
// Prevent extra closing tags for components without children
5980
'react/self-closing-comp': 'warn',
6081

environments/react/optional.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
ignoreCase: true,
2828
callbacksLast: false,
2929
requiredFirst: false,
30+
sortShapeProp: true,
3031
}],
3132

3233
// Forbid foreign propTypes

environments/react/recommended.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ module.exports = {
3434
// This rule enforces the consistent use of either double or single quotes in JSX attributes.
3535
'jsx-quotes': ['warn', 'prefer-double'],
3636

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+
3744
// Enforce boolean attributes notation in JSX
3845
// In JSX when using a boolean attribute you can set the attribute value to true or omit the
3946
// value. This rule will enforce one or the other to keep consistency in your code.
@@ -111,6 +118,12 @@ module.exports = {
111118
// results in in unnecessary renders.
112119
'react/no-array-index-key': 'warn',
113120

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+
114127
// Prevent usage of deprecated methods
115128
'react/no-deprecated': 'warn',
116129

@@ -168,6 +181,13 @@ module.exports = {
168181
// by setting a property on the this object in the reference callback is preferred.
169182
'react/no-string-refs': 'error',
170183

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+
171191
// Prevents common typos
172192
// This rule checks whether the declared static class properties and lifecycle methods related
173193
// to React components do not contain any typos.
@@ -179,6 +199,13 @@ module.exports = {
179199
// HTML.
180200
'react/no-unknown-property': 'error',
181201

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+
182209
// Prevent definitions of unused prop types
183210
// Warns you if you have defined a prop type but it is never being used anywhere.
184211
'react/no-unused-prop-types': ['error', {
@@ -188,7 +215,7 @@ module.exports = {
188215
}],
189216

190217
// Prevent definition of unused state fields
191-
'react/no-unused-state': ['warn'],
218+
'react/no-unused-state': 'warn',
192219

193220
// Enforce ES6 class for React Components
194221
'react/prefer-es6-class': ['error', 'always'],
@@ -215,7 +242,9 @@ module.exports = {
215242
// Enforce a `defaultProps` definition for every prop that is not a required prop
216243
// This rule aims to ensure that any non-required PropType declaration of a component has a
217244
// corresponding `defaultProps` value.
218-
'react/require-default-props': 'error',
245+
'react/require-default-props': ['error', {
246+
forbidDefaultForRequired: true,
247+
}],
219248

220249
// Enforce ES5 or ES6 class for returning value in render function
221250
// When writing the render method in a component it is easy to forget to return the JSX content.

0 commit comments

Comments
 (0)