Skip to content

Commit

Permalink
[fix] no-deprecated: Deprecate cWM/cWRP/cWU lifecycle methods since…
Browse files Browse the repository at this point in the history
… React 16.9.0
  • Loading branch information
meowtec authored and ljharb committed Aug 9, 2019
1 parent 57e2d72 commit 97a9f39
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
9 changes: 9 additions & 0 deletions docs/rules/no-deprecated.md
Expand Up @@ -27,6 +27,11 @@ const propTypes = {
React.DOM.div();

import React, { PropTypes } from 'react';

// old lifecycles (since React 16.9)
componentWillMount() { }
componentWillReceiveProps() { }
componentWillUpdate() { }
```

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

import { PropTypes } from 'prop-types';

UNSAFE_componentWillMount() { }
UNSAFE_componentWillReceiveProps() { }
UNSAFE_componentWillUpdate() { }
```
8 changes: 4 additions & 4 deletions lib/rules/no-deprecated.js
Expand Up @@ -76,24 +76,24 @@ module.exports = {
deprecated[`${pragma}.PropTypes`] = ['15.5.0', 'the npm module prop-types'];
// 15.6.0
deprecated[`${pragma}.DOM`] = ['15.6.0', 'the npm module react-dom-factories'];
// 16.999.0
// 16.9.0
// For now the following life-cycle methods are just legacy, not deprecated:
// `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`
// https://github.com/yannickcr/eslint-plugin-react/pull/1750#issuecomment-425975934
deprecated.componentWillMount = [
'16.999.0',
'16.9.0',
'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
];
deprecated.componentWillReceiveProps = [
'16.999.0',
'16.9.0',
'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
];
deprecated.componentWillUpdate = [
'16.999.0',
'16.9.0',
'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
Expand Down
44 changes: 22 additions & 22 deletions tests/lib/rules/no-deprecated.js
Expand Up @@ -94,7 +94,7 @@ ruleTester.run('no-deprecated', rule, {
componentWillUpdate() {}
}
`,
settings: {react: {version: '16.998.0'}}
settings: {react: {version: '16.8.0'}}
}
],

Expand Down Expand Up @@ -222,7 +222,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -232,7 +232,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -241,7 +241,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -264,7 +264,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -274,7 +274,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -283,7 +283,7 @@ ruleTester.run('no-deprecated', rule, {
column: 13
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -304,7 +304,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -314,7 +314,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -323,7 +323,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -344,7 +344,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -354,7 +354,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -363,7 +363,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -384,7 +384,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -394,7 +394,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -403,7 +403,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -424,7 +424,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -434,7 +434,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -443,7 +443,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -465,7 +465,7 @@ ruleTester.run('no-deprecated', rule, {
errors: [
{
message: errorMessage(
'componentWillMount', '16.999.0', 'UNSAFE_componentWillMount',
'componentWillMount', '16.9.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -475,7 +475,7 @@ ruleTester.run('no-deprecated', rule, {
},
{
message: errorMessage(
'componentWillReceiveProps', '16.999.0', 'UNSAFE_componentWillReceiveProps',
'componentWillReceiveProps', '16.9.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand All @@ -484,7 +484,7 @@ ruleTester.run('no-deprecated', rule, {
column: 11
},
{
message: errorMessage('componentWillUpdate', '16.999.0', 'UNSAFE_componentWillUpdate',
message: errorMessage('componentWillUpdate', '16.9.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate. ' +
'Use https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles to automatically update your components.'
),
Expand Down

0 comments on commit 97a9f39

Please sign in to comment.