Skip to content

Commit

Permalink
Added refs field to refer to docs inno-deprecated rule, minor adj…
Browse files Browse the repository at this point in the history
…ustments
  • Loading branch information
sergei-startsev committed Apr 1, 2018
1 parent 9e5643c commit 8d9ba75
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 140 deletions.
36 changes: 26 additions & 10 deletions lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MODULES = {
'react-addons-perf': ['ReactPerf', 'Perf']
};

const DEPRECATED_MESSAGE = '{{oldMethod}} is deprecated since React {{version}}{{newMethod}}';
const DEPRECATED_MESSAGE = '{{oldMethod}} is deprecated since React {{version}}{{newMethod}}{{refs}}';

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -77,9 +77,21 @@ module.exports = {
// 15.6.0
deprecated[`${pragma}.DOM`] = ['15.6.0', 'the npm module react-dom-factories'];
// 16.3.0
deprecated.componentWillMount = ['16.3.0'];
deprecated.componentWillReceiveProps = ['16.3.0'];
deprecated.componentWillUpdate = ['16.3.0'];
deprecated.componentWillMount = [
'16.3.0',
'constructor',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
];
deprecated.componentWillReceiveProps = [
'16.3.0',
'getDerivedStateFromProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
];
deprecated.componentWillUpdate = [
'16.3.0',
'getDerivedStateFromProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
];
return deprecated;
}

Expand All @@ -98,13 +110,17 @@ module.exports = {
return;
}
const deprecated = getDeprecated();
const version = deprecated[method][0];
const newMethod = deprecated[method][1];
const refs = deprecated[method][2];
context.report({
node: node,
message: DEPRECATED_MESSAGE,
data: {
oldMethod: method,
version: deprecated[method][0],
newMethod: deprecated[method][1] ? `, use ${deprecated[method][1]} instead` : ''
version,
newMethod: newMethod ? `, use ${newMethod} instead` : '',
refs: refs ? `, see ${refs}` : ''
}
});
}
Expand Down Expand Up @@ -153,11 +169,11 @@ module.exports = {

return {

MemberExpression: function(node) {
MemberExpression: function (node) {
checkDeprecation(node, sourceCode.getText(node));
},

ImportDeclaration: function(node) {
ImportDeclaration: function (node) {
const isReactImport = typeof MODULES[node.source.value] !== 'undefined';
if (!isReactImport) {
return;
Expand All @@ -170,13 +186,13 @@ module.exports = {
});
},

VariableDeclarator: function(node) {
VariableDeclarator: function (node) {
const reactModuleName = getReactModuleName(node);
const isRequire = node.init && node.init.callee && node.init.callee.name === 'require';
const isReactRequire =
node.init && node.init.arguments &&
node.init.arguments.length && typeof MODULES[node.init.arguments[0].value] !== 'undefined'
;
;
const isDestructuring = node.id && node.id.type === 'ObjectPattern';

if (
Expand Down
Loading

0 comments on commit 8d9ba75

Please sign in to comment.