Skip to content

Commit ff1c121

Browse files
committed
[eslint config] [breaking] update eslint-plugin-react to v7.6; update rule configs
1 parent 901fd85 commit ff1c121

File tree

2 files changed

+95
-18
lines changed

2 files changed

+95
-18
lines changed

packages/eslint-config-airbnb/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"eslint-find-rules": "^3.1.1",
5959
"eslint-plugin-import": "^2.8.0",
6060
"eslint-plugin-jsx-a11y": "^6.0.3",
61-
"eslint-plugin-react": "^7.4.0",
61+
"eslint-plugin-react": "^7.6.1",
6262
"in-publish": "^2.0.0",
6363
"react": ">= 0.13.0",
6464
"safe-publish-latest": "^1.1.1",
@@ -68,7 +68,7 @@
6868
"eslint": "^4.16.0",
6969
"eslint-plugin-import": "^2.8.0",
7070
"eslint-plugin-jsx-a11y": "^6.0.3",
71-
"eslint-plugin-react": "^7.4.0"
71+
"eslint-plugin-react": "^7.6.1"
7272
},
7373
"engines": {
7474
"node": ">= 4"

packages/eslint-config-airbnb/rules/react.js

+93-16
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ module.exports = {
3838
'react/display-name': ['off', { ignoreTranspilerName: false }],
3939

4040
// Forbid certain propTypes (any, array, object)
41-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
42-
'react/forbid-prop-types': ['error', { forbid: ['any', 'array', 'object'] }],
41+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-prop-types.md
42+
'react/forbid-prop-types': ['error', {
43+
forbid: ['any', 'array', 'object'],
44+
checkContextTypes: true,
45+
checkChildContextTypes: true,
46+
}],
47+
48+
// Forbid certain props on DOM Nodes
49+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-dom-props.md
50+
'react/forbid-dom-props': ['off', { forbid: [] }],
4351

4452
// Enforce boolean attributes notation in JSX
4553
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
@@ -109,6 +117,7 @@ module.exports = {
109117
ignoreCase: true,
110118
callbacksLast: false,
111119
requiredFirst: false,
120+
sortShapeProp: true,
112121
}],
113122

114123
// Deprecated in favor of react/jsx-sort-props
@@ -125,6 +134,12 @@ module.exports = {
125134
reservedFirst: true,
126135
}],
127136

137+
// Enforce defaultProps declarations alphabetical sorting
138+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-sort-default-props.md
139+
'react/jsx-sort-default-props': ['off', {
140+
ignoreCase: true,
141+
}],
142+
128143
// Prevent React to be incorrectly marked as unused
129144
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
130145
'react/jsx-uses-react': ['error'],
@@ -207,28 +222,59 @@ module.exports = {
207222
'react/self-closing-comp': 'error',
208223

209224
// Enforce component methods order
210-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
225+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/sort-comp.md
211226
'react/sort-comp': ['error', {
212227
order: [
213228
'static-methods',
229+
'instance-variables',
214230
'lifecycle',
215231
'/^on.+$/',
216232
'getters',
217233
'setters',
218234
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
235+
'instance-methods',
219236
'everything-else',
220-
'/^render.+$/',
221-
'render'
237+
'rendering',
222238
],
239+
groups: {
240+
lifecycle: [
241+
'displayName',
242+
'propTypes',
243+
'contextTypes',
244+
'childContextTypes',
245+
'mixins',
246+
'statics',
247+
'defaultProps',
248+
'constructor',
249+
'getDefaultProps',
250+
'getInitialState',
251+
'state',
252+
'getChildContext',
253+
'componentWillMount',
254+
'componentDidMount',
255+
'componentWillReceiveProps',
256+
'shouldComponentUpdate',
257+
'componentWillUpdate',
258+
'componentDidUpdate',
259+
'componentWillUnmount',
260+
],
261+
rendering: [
262+
'/^render.+$/',
263+
'render'
264+
],
265+
},
223266
}],
224267

225268
// Prevent missing parentheses around multilines JSX
226-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
269+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-wrap-multilines.md
227270
'react/jsx-wrap-multilines': ['error', {
228-
declaration: true,
229-
assignment: true,
230-
return: true,
231-
arrow: true,
271+
declaration: 'parens-new-line',
272+
assignment: 'parens-new-line',
273+
return: 'parens-new-line',
274+
arrow: 'parens-new-line',
275+
condition: 'parens-new-line',
276+
logical: 'parens-new-line',
277+
prop: 'parens-new-line',
232278
}],
233279

234280
// Require that the first prop in a JSX element be on a new line when the element is multiline
@@ -300,11 +346,12 @@ module.exports = {
300346
'react/no-children-prop': 'error',
301347

302348
// Validate whitespace in and around the JSX opening and closing brackets
303-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md
349+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-tag-spacing.md
304350
'react/jsx-tag-spacing': ['error', {
305351
closingSlash: 'never',
306352
beforeSelfClosing: 'always',
307-
afterOpening: 'never'
353+
afterOpening: 'never',
354+
beforeClosing: 'never',
308355
}],
309356

310357
// Enforce spaces before the closing bracket of self-closing JSX elements
@@ -317,8 +364,10 @@ module.exports = {
317364
'react/no-array-index-key': 'error',
318365

319366
// Enforce a defaultProps definition for every prop that is not a required prop
320-
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
321-
'react/require-default-props': 'error',
367+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/require-default-props.md
368+
'react/require-default-props': ['error', {
369+
forbidDefaultForRequired: true,
370+
}],
322371

323372
// Forbids using non-exported propTypes
324373
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md
@@ -341,10 +390,11 @@ module.exports = {
341390
'react/no-unused-state': 'error',
342391

343392
// Enforces consistent naming for boolean props
344-
// https://github.com/yannickcr/eslint-plugin-react/blob/73abadb697034b5ccb514d79fb4689836fe61f91/docs/rules/boolean-prop-naming.md
393+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/boolean-prop-naming.md
345394
'react/boolean-prop-naming': ['off', {
346395
propTypeNames: ['bool', 'mutuallyExclusiveTrueProps'],
347396
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
397+
message: '',
348398
}],
349399

350400
// Prevents common casing typos
@@ -353,7 +403,34 @@ module.exports = {
353403

354404
// Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children
355405
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
356-
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }]
406+
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
407+
408+
// One JSX Element Per Line
409+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-one-expression-per-line.md
410+
'react/jsx-one-expression-per-line': 'error',
411+
412+
// Enforce consistent usage of destructuring assignment of props, state, and context
413+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/destructuring-assignment.md
414+
'react/destructuring-assignment': ['error', 'always'],
415+
416+
// Prevent using this.state within a this.setState
417+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-access-state-in-setstate.md
418+
'react/no-access-state-in-setstate': 'error',
419+
420+
// Prevent usage of button elements without an explicit type attribute
421+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/button-has-type.md
422+
'react/button-has-type': ['error', {
423+
button: true,
424+
submit: true,
425+
reset: false,
426+
}],
427+
428+
// Ensures inline tags are not rendered without spaces between them
429+
'react/jsx-child-element-spacing': 'off',
430+
431+
// Prevent this from being used in stateless functional components
432+
// https://github.com/yannickcr/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/no-this-in-sfc.md
433+
'react/no-this-in-sfc': 'error',
357434
},
358435

359436
settings: {

0 commit comments

Comments
 (0)