|
2 | 2 | * @fileoverview Prevent usage of deprecated methods
|
3 | 3 | * @author Yannick Croissant
|
4 | 4 | * @author Scott Feeney
|
| 5 | + * @author Sergei Startsev |
5 | 6 | */
|
6 | 7 | 'use strict';
|
7 | 8 |
|
8 | 9 | const has = require('has');
|
9 | 10 |
|
| 11 | +const Components = require('../util/Components'); |
| 12 | +const astUtil = require('../util/ast'); |
| 13 | +const docsUrl = require('../util/docsUrl'); |
10 | 14 | const pragmaUtil = require('../util/pragma');
|
11 | 15 | const versionUtil = require('../util/version');
|
12 |
| -const docsUrl = require('../util/docsUrl'); |
13 | 16 |
|
14 | 17 | // ------------------------------------------------------------------------------
|
15 | 18 | // Constants
|
@@ -37,7 +40,7 @@ module.exports = {
|
37 | 40 | schema: []
|
38 | 41 | },
|
39 | 42 |
|
40 |
| - create: function(context) { |
| 43 | + create: Components.detect((context, components, utils) => { |
41 | 44 | const sourceCode = context.getSourceCode();
|
42 | 45 | const pragma = pragmaUtil.getFromContext(context);
|
43 | 46 |
|
@@ -73,6 +76,10 @@ module.exports = {
|
73 | 76 | deprecated[`${pragma}.PropTypes`] = ['15.5.0', 'the npm module prop-types'];
|
74 | 77 | // 15.6.0
|
75 | 78 | deprecated[`${pragma}.DOM`] = ['15.6.0', 'the npm module react-dom-factories'];
|
| 79 | + // 16.3.0 |
| 80 | + deprecated.componentWillMount = ['16.3.0']; |
| 81 | + deprecated.componentWillReceiveProps = ['16.3.0']; |
| 82 | + deprecated.componentWillUpdate = ['16.3.0']; |
76 | 83 | return deprecated;
|
77 | 84 | }
|
78 | 85 |
|
@@ -119,6 +126,27 @@ module.exports = {
|
119 | 126 | return moduleName;
|
120 | 127 | }
|
121 | 128 |
|
| 129 | + /** |
| 130 | + * Returns life cycle methods if available |
| 131 | + * @param {ASTNode} node The AST node being checked. |
| 132 | + * @returns {Array} The array of methods. |
| 133 | + */ |
| 134 | + function getLifeCycleMethods(node) { |
| 135 | + const properties = astUtil.getComponentProperties(node); |
| 136 | + return properties.map(property => astUtil.getPropertyName(property)); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Checks life cycle methods |
| 141 | + * @param {ASTNode} node The AST node being checked. |
| 142 | + */ |
| 143 | + function checkLifeCycleMethods(node) { |
| 144 | + if (utils.isES5Component(node) || utils.isES6Component(node)) { |
| 145 | + const methods = getLifeCycleMethods(node); |
| 146 | + methods.forEach(method => checkDeprecation(node, method)); |
| 147 | + } |
| 148 | + } |
| 149 | + |
122 | 150 | // --------------------------------------------------------------------------
|
123 | 151 | // Public
|
124 | 152 | // --------------------------------------------------------------------------
|
@@ -160,8 +188,11 @@ module.exports = {
|
160 | 188 | node.id.properties.forEach(property => {
|
161 | 189 | checkDeprecation(node, `${reactModuleName || pragma}.${property.key.name}`);
|
162 | 190 | });
|
163 |
| - } |
| 191 | + }, |
164 | 192 |
|
| 193 | + ClassDeclaration: checkLifeCycleMethods, |
| 194 | + ClassExpression: checkLifeCycleMethods, |
| 195 | + ObjectExpression: checkLifeCycleMethods |
165 | 196 | };
|
166 |
| - } |
| 197 | + }) |
167 | 198 | };
|
0 commit comments