Skip to content

Commit c29807c

Browse files
authored
Merge pull request #1786 from taddei/master
Hotfix - fix no-deprecated bug
2 parents fb7411d + e57ca07 commit c29807c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/rules/no-deprecated.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ module.exports = {
101101
return (
102102
deprecated &&
103103
deprecated[method] &&
104+
deprecated[method][0] &&
104105
versionUtil.testReactVersion(context, deprecated[method][0])
105106
);
106107
}

lib/util/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function getFlowVersionFromContext(context) {
2727
}
2828

2929
function test(context, methodVer, confVer) {
30-
methodVer = methodVer.split('.').map(part => Number(part));
30+
methodVer = String(methodVer || '').split('.').map(part => Number(part));
3131
const higherMajor = methodVer[0] < confVer[0];
3232
const higherMinor = methodVer[0] === confVer[0] && methodVer[1] < confVer[1];
3333
const higherOrEqualPatch = methodVer[0] === confVer[0] && methodVer[1] === confVer[1] && methodVer[2] <= confVer[2];

tests/lib/rules/no-deprecated.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ ruleTester.run('no-deprecated', rule, {
7575
{
7676
code: `
7777
class Foo {
78+
constructor() {}
7879
componentWillMount() {}
7980
componentWillReceiveProps() {}
8081
componentWillUpdate() {}
@@ -379,6 +380,35 @@ ruleTester.run('no-deprecated', rule, {
379380
)
380381
}
381382
]
383+
},
384+
{
385+
code: `
386+
class Foo extends React.Component {
387+
constructor() {}
388+
componentWillMount() {}
389+
componentWillReceiveProps() {}
390+
componentWillUpdate() {}
391+
}
392+
`,
393+
errors: [
394+
{
395+
message: errorMessage(
396+
'componentWillMount', '16.3.0', 'UNSAFE_componentWillMount',
397+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillmount'
398+
)
399+
},
400+
{
401+
message: errorMessage(
402+
'componentWillReceiveProps', '16.3.0', 'UNSAFE_componentWillReceiveProps',
403+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops'
404+
)
405+
},
406+
{
407+
message: errorMessage('componentWillUpdate', '16.3.0', 'UNSAFE_componentWillUpdate',
408+
'https://reactjs.org/docs/react-component.html#unsafe_componentwillupdate'
409+
)
410+
}
411+
]
382412
}
383413
]
384414
});

0 commit comments

Comments
 (0)