Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate old lifecycles since React 16.9.0 #2378

Merged
merged 1 commit into from Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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