Repository: yannickcr/eslint-plugin-react
Pull request #1148 (2017-04-11 11:26:00)

Add new deprecations from 15.5.0
Added more deprecations rules regarding last react update.

But it does not seem to match patterns like this:
```javascript
import { PropTypes, createClass } from 'react';
```

Any idea on how we can match those too?


Patch:
diff --git a/docs/rules/no-deprecated.md b/docs/rules/no-deprecated.md
index 2ca55416..8e168543 100644
--- a/docs/rules/no-deprecated.md
+++ b/docs/rules/no-deprecated.md
@@ -16,6 +16,12 @@ React.findDOMNode(this.refs.foo);
 React.renderToString(<MyComponent />);
 
 React.renderToStaticMarkup(<MyComponent />);
+
+React.createClass({ /* Class object */ });
+
+const propTypes = {
+  foo: React.PropTypes.bar,
+};
 ```
 
 The following patterns are not considered warnings:
diff --git a/lib/rules/no-deprecated.js b/lib/rules/no-deprecated.js
index 4552a4f6..be063e91 100644
--- a/lib/rules/no-deprecated.js
+++ b/lib/rules/no-deprecated.js
@@ -64,6 +64,9 @@ module.exports = {
       deprecated.MemberExpression['Perf.printDOM'] = ['15.0.0', 'Perf.printOperations'];
       deprecated.MemberExpression['ReactPerf.getMeasurementsSummaryMap'] = ['15.0.0', 'ReactPerf.getWasted'];
       deprecated.MemberExpression['Perf.getMeasurementsSummaryMap'] = ['15.0.0', 'Perf.getWasted'];
+      // 15.5.0
+      deprecated.MemberExpression[pragma + '.createClass'] = ['15.5.0', 'the npm module create-react-class'];
+      deprecated.MemberExpression[pragma + '.PropTypes'] = ['15.5.0', 'the npm module prop-types'];
 
       return deprecated;
     }


Test patch:
diff --git a/tests/lib/rules/no-deprecated.js b/tests/lib/rules/no-deprecated.js
index 6a775767..8ebb3ce8 100644
--- a/tests/lib/rules/no-deprecated.js
+++ b/tests/lib/rules/no-deprecated.js
@@ -23,7 +23,6 @@ ruleTester.run('no-deprecated', rule, {
 
   valid: [
     // Not deprecated
-    'var MyClass = React.createClass({});',
     'var element = React.createElement(\'p\', {}, null);',
     'var clone = React.cloneElement(element);',
     'ReactDOM.render(element, container);',
@@ -32,7 +31,9 @@ ruleTester.run('no-deprecated', rule, {
     'ReactDOMServer.renderToString(element);',
     'ReactDOMServer.renderToStaticMarkup(element);',
     // Deprecated in a later version
-    {code: 'React.renderComponent()', settings: {react: {version: '0.11.0'}}}
+    {code: 'React.renderComponent()', settings: {react: {version: '0.11.0'}}},
+    {code: 'React.createClass()', settings: {react: {version: '15.4.0'}}},
+    {code: 'React.PropTypes', settings: {react: {version: '15.4.0'}}}
   ],
 
   invalid: [{
@@ -94,6 +95,22 @@ ruleTester.run('no-deprecated', rule, {
         'use ReactDOMServer.renderToStaticMarkup instead'
       )
     }]
+  }, {
+    code: 'React.createClass({});',
+    errors: [{
+      message: 'React.createClass is deprecated since React 15.5.0, use the npm module create-react-class instead'
+    }]
+  }, {
+    code: 'Foo.createClass({});',
+    settings: {react: {pragma: 'Foo'}},
+    errors: [{
+      message: 'Foo.createClass is deprecated since React 15.5.0, use the npm module create-react-class instead'
+    }]
+  }, {
+    code: 'React.PropTypes',
+    errors: [{
+      message: 'React.PropTypes is deprecated since React 15.5.0, use the npm module prop-types instead'
+    }]
   }]
 
 });