Skip to content

Commit 70d4e71

Browse files
Exclude legacy life-cycle methods fromno-deprecated rule for now
- Exclude legacy life-cycle methods from`no-deprecated` rule until it's decided which release deprecates them. - Add details regarding `rename-unsafe-lifecycles` codemod to automatically update components
1 parent 6d9e7bb commit 70d4e71

File tree

3 files changed

+77
-77
lines changed

3 files changed

+77
-77
lines changed

docs/rules/no-deprecated.md

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

2929
import React, { PropTypes } from 'react';
30-
31-
class Foo extends React.Component {
32-
componentWillMount() { }
33-
componentWillReceiveProps() { }
34-
componentWillUpdate() { }
35-
// ...
36-
}
37-
38-
class Foo extends React.PureComponent {
39-
componentWillMount() { }
40-
componentWillReceiveProps() { }
41-
componentWillUpdate() { }
42-
// ...
43-
}
44-
45-
var Foo = createReactClass({
46-
componentWillMount: function() {},
47-
componentWillReceiveProps: function() {},
48-
componentWillUpdate: function() {},
49-
// ...
50-
})
5130
```
5231

5332
The following patterns are **not** considered warnings:
@@ -59,10 +38,4 @@ ReactDOM.render(<MyComponent />, root);
5938
ReactDOM.findDOMNode(this.refs.foo);
6039

6140
import { PropTypes } from 'prop-types';
62-
63-
class Foo {
64-
componentWillMount() { }
65-
componentWillReceiveProps() { }
66-
componentWillUpdate() { }
67-
}
6841
```

lib/rules/no-deprecated.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,27 @@ 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.3.0
79+
// 16.999.0
80+
// For now the following life-cycle methods are just legacy, not deprecated:
81+
// `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`
82+
// https://github.com/yannickcr/eslint-plugin-react/pull/1750#issuecomment-425975934
8083
deprecated.componentWillMount = [
81-
'16.3.0',
84+
'16.999.0',
8285
'UNSAFE_componentWillMount',
83-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
86+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
87+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
8488
];
8589
deprecated.componentWillReceiveProps = [
86-
'16.3.0',
90+
'16.999.0',
8791
'UNSAFE_componentWillReceiveProps',
88-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
92+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
93+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
8994
];
9095
deprecated.componentWillUpdate = [
91-
'16.3.0',
96+
'16.999.0',
9297
'UNSAFE_componentWillUpdate',
93-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
98+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
99+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
94100
];
95101
return deprecated;
96102
}

tests/lib/rules/no-deprecated.js

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ruleTester.run('no-deprecated', rule, {
9191
componentWillUpdate() {}
9292
}
9393
`,
94-
settings: {react: {version: '16.2.0'}}
94+
settings: {react: {version: '16.998.0'}}
9595
}
9696
],
9797

@@ -219,25 +219,28 @@ ruleTester.run('no-deprecated', rule, {
219219
errors: [
220220
{
221221
message: errorMessage(
222-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
223-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
222+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
223+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
224+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
224225
),
225226
type: 'Identifier',
226227
line: 3,
227228
column: 11
228229
},
229230
{
230231
message: errorMessage(
231-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
232-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
232+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
233+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
234+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
233235
),
234236
type: 'Identifier',
235237
line: 4,
236238
column: 11
237239
},
238240
{
239-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
240-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
241+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
242+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
243+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
241244
),
242245
type: 'Identifier',
243246
line: 5,
@@ -258,25 +261,28 @@ ruleTester.run('no-deprecated', rule, {
258261
errors: [
259262
{
260263
message: errorMessage(
261-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
262-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
264+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
265+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
266+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
263267
),
264268
type: 'Identifier',
265269
line: 4,
266270
column: 13
267271
},
268272
{
269273
message: errorMessage(
270-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
271-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
274+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
275+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
276+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
272277
),
273278
type: 'Identifier',
274279
line: 5,
275280
column: 13
276281
},
277282
{
278-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
279-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
283+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
284+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
285+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
280286
),
281287
type: 'Identifier',
282288
line: 6,
@@ -295,25 +301,28 @@ ruleTester.run('no-deprecated', rule, {
295301
errors: [
296302
{
297303
message: errorMessage(
298-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
299-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
304+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
305+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
306+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
300307
),
301308
type: 'Identifier',
302309
line: 3,
303310
column: 11
304311
},
305312
{
306313
message: errorMessage(
307-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
308-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
314+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
315+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
316+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
309317
),
310318
type: 'Identifier',
311319
line: 4,
312320
column: 11
313321
},
314322
{
315-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
316-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
323+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
324+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
325+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
317326
),
318327
type: 'Identifier',
319328
line: 5,
@@ -332,25 +341,28 @@ ruleTester.run('no-deprecated', rule, {
332341
errors: [
333342
{
334343
message: errorMessage(
335-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
336-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
344+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
345+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
346+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
337347
),
338348
type: 'Identifier',
339349
line: 3,
340350
column: 11
341351
},
342352
{
343353
message: errorMessage(
344-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
345-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
354+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
355+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
356+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
346357
),
347358
type: 'Identifier',
348359
line: 4,
349360
column: 11
350361
},
351362
{
352-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
353-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
363+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
364+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
365+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
354366
),
355367
type: 'Identifier',
356368
line: 5,
@@ -369,25 +381,28 @@ ruleTester.run('no-deprecated', rule, {
369381
errors: [
370382
{
371383
message: errorMessage(
372-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
373-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
384+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
385+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
386+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
374387
),
375388
type: 'Identifier',
376389
line: 3,
377390
column: 11
378391
},
379392
{
380393
message: errorMessage(
381-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
382-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
394+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
395+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
396+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
383397
),
384398
type: 'Identifier',
385399
line: 4,
386400
column: 11
387401
},
388402
{
389-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
390-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
403+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
404+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
405+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
391406
),
392407
type: 'Identifier',
393408
line: 5,
@@ -406,25 +421,28 @@ ruleTester.run('no-deprecated', rule, {
406421
errors: [
407422
{
408423
message: errorMessage(
409-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
410-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
424+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
425+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
426+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
411427
),
412428
type: 'Identifier',
413429
line: 3,
414430
column: 11
415431
},
416432
{
417433
message: errorMessage(
418-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
419-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
434+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
435+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
436+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
420437
),
421438
type: 'Identifier',
422439
line: 4,
423440
column: 11
424441
},
425442
{
426-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
427-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
443+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
444+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
445+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
428446
),
429447
type: 'Identifier',
430448
line: 5,
@@ -444,25 +462,28 @@ ruleTester.run('no-deprecated', rule, {
444462
errors: [
445463
{
446464
message: errorMessage(
447-
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
448-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
465+
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
466+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
467+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
449468
),
450469
type: 'Identifier',
451470
line: 4,
452471
column: 11
453472
},
454473
{
455474
message: errorMessage(
456-
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
457-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
475+
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
476+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
477+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
458478
),
459479
type: 'Identifier',
460480
line: 5,
461481
column: 11
462482
},
463483
{
464-
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
465-
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
484+
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
485+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
486+
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
466487
),
467488
type: 'Identifier',
468489
line: 6,

0 commit comments

Comments
 (0)