Skip to content

Commit 501edbf

Browse files
sergei-startsevljharb
authored andcommitted
Added refs field to refer to docs inno-deprecated rule, minor adjustments
1 parent 5ab7a23 commit 501edbf

File tree

2 files changed

+178
-140
lines changed

2 files changed

+178
-140
lines changed

lib/rules/no-deprecated.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const MODULES = {
2323
'react-addons-perf': ['ReactPerf', 'Perf']
2424
};
2525

26-
const DEPRECATED_MESSAGE = '{{oldMethod}} is deprecated since React {{version}}{{newMethod}}';
26+
const DEPRECATED_MESSAGE = '{{oldMethod}} is deprecated since React {{version}}{{newMethod}}{{refs}}';
2727

2828
// ------------------------------------------------------------------------------
2929
// Rule Definition
@@ -77,9 +77,21 @@ module.exports = {
7777
// 15.6.0
7878
deprecated[`${pragma}.DOM`] = ['15.6.0', 'the npm module react-dom-factories'];
7979
// 16.3.0
80-
deprecated.componentWillMount = ['16.3.0'];
81-
deprecated.componentWillReceiveProps = ['16.3.0'];
82-
deprecated.componentWillUpdate = ['16.3.0'];
80+
deprecated.componentWillMount = [
81+
'16.3.0',
82+
'constructor',
83+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
84+
];
85+
deprecated.componentWillReceiveProps = [
86+
'16.3.0',
87+
'getDerivedStateFromProps',
88+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
89+
];
90+
deprecated.componentWillUpdate = [
91+
'16.3.0',
92+
'getDerivedStateFromProps',
93+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
94+
];
8395
return deprecated;
8496
}
8597

@@ -98,13 +110,17 @@ module.exports = {
98110
return;
99111
}
100112
const deprecated = getDeprecated();
113+
const version = deprecated[method][0];
114+
const newMethod = deprecated[method][1];
115+
const refs = deprecated[method][2];
101116
context.report({
102117
node: node,
103118
message: DEPRECATED_MESSAGE,
104119
data: {
105120
oldMethod: method,
106-
version: deprecated[method][0],
107-
newMethod: deprecated[method][1] ? `, use ${deprecated[method][1]} instead` : ''
121+
version,
122+
newMethod: newMethod ? `, use ${newMethod} instead` : '',
123+
refs: refs ? `, see ${refs}` : ''
108124
}
109125
});
110126
}
@@ -173,10 +189,10 @@ module.exports = {
173189
VariableDeclarator: function(node) {
174190
const reactModuleName = getReactModuleName(node);
175191
const isRequire = node.init && node.init.callee && node.init.callee.name === 'require';
176-
const isReactRequire =
177-
node.init && node.init.arguments &&
178-
node.init.arguments.length && typeof MODULES[node.init.arguments[0].value] !== 'undefined'
179-
;
192+
const isReactRequire = node.init
193+
&& node.init.arguments
194+
&& node.init.arguments.length
195+
&& typeof MODULES[node.init.arguments[0].value] !== 'undefined';
180196
const isDestructuring = node.id && node.id.type === 'ObjectPattern';
181197

182198
if (

0 commit comments

Comments
 (0)