Skip to content

Commit

Permalink
Merge pull request #1786 from taddei/master
Browse files Browse the repository at this point in the history
Hotfix - fix no-deprecated bug
  • Loading branch information
ljharb committed May 11, 2018
2 parents fb7411d + e57ca07 commit c29807c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rules/no-deprecated.js
Expand Up @@ -101,6 +101,7 @@ module.exports = {
return (
deprecated &&
deprecated[method] &&
deprecated[method][0] &&
versionUtil.testReactVersion(context, deprecated[method][0])
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/version.js
Expand Up @@ -27,7 +27,7 @@ function getFlowVersionFromContext(context) {
}

function test(context, methodVer, confVer) {
methodVer = methodVer.split('.').map(part => Number(part));
methodVer = String(methodVer || '').split('.').map(part => Number(part));
const higherMajor = methodVer[0] < confVer[0];
const higherMinor = methodVer[0] === confVer[0] && methodVer[1] < confVer[1];
const higherOrEqualPatch = methodVer[0] === confVer[0] && methodVer[1] === confVer[1] && methodVer[2] <= confVer[2];
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/rules/no-deprecated.js
Expand Up @@ -75,6 +75,7 @@ ruleTester.run('no-deprecated', rule, {
{
code: `
class Foo {
constructor() {}
componentWillMount() {}
componentWillReceiveProps() {}
componentWillUpdate() {}
Expand Down Expand Up @@ -379,6 +380,35 @@ ruleTester.run('no-deprecated', rule, {
)
}
]
},
{
code: `
class Foo extends React.Component {
constructor() {}
componentWillMount() {}
componentWillReceiveProps() {}
componentWillUpdate() {}
}
`,
errors: [
{
message: errorMessage(
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
)
},
{
message: errorMessage(
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
)
},
{
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
)
}
]
}
]
});

0 comments on commit c29807c

Please sign in to comment.