Skip to content

Commit 2b74d30

Browse files
committed
Deprecate componentWillMount/componentWillReceiveProps/componentWillUpdate lifecycles since React 16.9.0
1 parent 1aab93d commit 2b74d30

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

docs/rules/no-deprecated.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const propTypes = {
2727
React.DOM.div();
2828

2929
import React, { PropTypes } from 'react';
30+
31+
// old lifecycles (since React 16.9)
32+
componentWillMount() { }
33+
componentWillReceiveProps() { }
34+
componentWillUpdate() { }
3035
```
3136

3237
The following patterns are **not** considered warnings:
@@ -38,4 +43,8 @@ ReactDOM.render(<MyComponent />, root);
3843
ReactDOM.findDOMNode(this.refs.foo);
3944

4045
import { PropTypes } from 'prop-types';
46+
47+
UNSAFE_componentWillMount() { }
48+
UNSAFE_componentWillReceiveProps() { }
49+
UNSAFE_componentWillUpdate() { }
4150
```

lib/rules/no-deprecated.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@ module.exports = {
7676
deprecated[`${pragma}.PropTypes`] = ['15.5.0', 'the npm module prop-types'];
7777
// 15.6.0
7878
deprecated[`${pragma}.DOM`] = ['15.6.0', 'the npm module react-dom-factories'];
79-
// 16.999.0
79+
// 16.9.0
8080
// For now the following life-cycle methods are just legacy, not deprecated:
8181
// `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`
8282
// https://github.com/yannickcr/eslint-plugin-react/pull/1750#issuecomment-425975934
8383
deprecated.componentWillMount = [
84-
'16.999.0',
84+
'16.9.0',
8585
'UNSAFE_componentWillMount',
8686
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
8787
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
8888
];
8989
deprecated.componentWillReceiveProps = [
90-
'16.999.0',
90+
'16.9.0',
9191
'UNSAFE_componentWillReceiveProps',
9292
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
9393
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
9494
];
9595
deprecated.componentWillUpdate = [
96-
'16.999.0',
96+
'16.9.0',
9797
'UNSAFE_componentWillUpdate',
9898
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
9999
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'

tests/lib/rules/no-deprecated.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ruleTester.run('no-deprecated', rule, {
9494
componentWillUpdate() {}
9595
}
9696
`,
97-
settings: {react: {version: '16.998.0'}}
97+
settings: {react: {version: '16.8.0'}}
9898
}
9999
],
100100

@@ -222,7 +222,7 @@ ruleTester.run('no-deprecated', rule, {
222222
errors: [
223223
{
224224
message: errorMessage(
225-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
225+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
226226
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
227227
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
228228
),
@@ -232,7 +232,7 @@ ruleTester.run('no-deprecated', rule, {
232232
},
233233
{
234234
message: errorMessage(
235-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
235+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
236236
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
237237
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
238238
),
@@ -241,7 +241,7 @@ ruleTester.run('no-deprecated', rule, {
241241
column: 11
242242
},
243243
{
244-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
244+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
245245
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
246246
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
247247
),
@@ -264,7 +264,7 @@ ruleTester.run('no-deprecated', rule, {
264264
errors: [
265265
{
266266
message: errorMessage(
267-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
267+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
268268
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
269269
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
270270
),
@@ -274,7 +274,7 @@ ruleTester.run('no-deprecated', rule, {
274274
},
275275
{
276276
message: errorMessage(
277-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
277+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
278278
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
279279
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
280280
),
@@ -283,7 +283,7 @@ ruleTester.run('no-deprecated', rule, {
283283
column: 13
284284
},
285285
{
286-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
286+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
287287
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
288288
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
289289
),
@@ -304,7 +304,7 @@ ruleTester.run('no-deprecated', rule, {
304304
errors: [
305305
{
306306
message: errorMessage(
307-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
307+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
308308
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
309309
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
310310
),
@@ -314,7 +314,7 @@ ruleTester.run('no-deprecated', rule, {
314314
},
315315
{
316316
message: errorMessage(
317-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
317+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
318318
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
319319
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
320320
),
@@ -323,7 +323,7 @@ ruleTester.run('no-deprecated', rule, {
323323
column: 11
324324
},
325325
{
326-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
326+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
327327
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
328328
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
329329
),
@@ -344,7 +344,7 @@ ruleTester.run('no-deprecated', rule, {
344344
errors: [
345345
{
346346
message: errorMessage(
347-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
347+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
348348
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
349349
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
350350
),
@@ -354,7 +354,7 @@ ruleTester.run('no-deprecated', rule, {
354354
},
355355
{
356356
message: errorMessage(
357-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
357+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
358358
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
359359
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
360360
),
@@ -363,7 +363,7 @@ ruleTester.run('no-deprecated', rule, {
363363
column: 11
364364
},
365365
{
366-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
366+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
367367
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
368368
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
369369
),
@@ -384,7 +384,7 @@ ruleTester.run('no-deprecated', rule, {
384384
errors: [
385385
{
386386
message: errorMessage(
387-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
387+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
388388
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
389389
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
390390
),
@@ -394,7 +394,7 @@ ruleTester.run('no-deprecated', rule, {
394394
},
395395
{
396396
message: errorMessage(
397-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
397+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
398398
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
399399
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
400400
),
@@ -403,7 +403,7 @@ ruleTester.run('no-deprecated', rule, {
403403
column: 11
404404
},
405405
{
406-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
406+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
407407
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
408408
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
409409
),
@@ -424,7 +424,7 @@ ruleTester.run('no-deprecated', rule, {
424424
errors: [
425425
{
426426
message: errorMessage(
427-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
427+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
428428
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
429429
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
430430
),
@@ -434,7 +434,7 @@ ruleTester.run('no-deprecated', rule, {
434434
},
435435
{
436436
message: errorMessage(
437-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
437+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
438438
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
439439
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
440440
),
@@ -443,7 +443,7 @@ ruleTester.run('no-deprecated', rule, {
443443
column: 11
444444
},
445445
{
446-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
446+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
447447
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
448448
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
449449
),
@@ -465,7 +465,7 @@ ruleTester.run('no-deprecated', rule, {
465465
errors: [
466466
{
467467
message: errorMessage(
468-
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
468+
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
469469
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
470470
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
471471
),
@@ -475,7 +475,7 @@ ruleTester.run('no-deprecated', rule, {
475475
},
476476
{
477477
message: errorMessage(
478-
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
478+
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
479479
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
480480
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
481481
),
@@ -484,7 +484,7 @@ ruleTester.run('no-deprecated', rule, {
484484
column: 11
485485
},
486486
{
487-
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
487+
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
488488
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
489489
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
490490
),

0 commit comments

Comments
 (0)