Closed
Description
Given a React component like:
export default class Thing extends React.Component {
static propTypes = {
i18n: PropTypes.shape({
gettext: PropTypes.func,
}).isRequired,
}
render() {
const { i18n } = this.props;
return (
<div>
<span>{i18n.gettext('Some Text')}</span>
</div>
);
}
}
And the following eslint rule:
"react/no-unused-prop-types": "error"
I see the following error:
/Users/kumar/tmp/eslint-scratch/index.js
6:16 error 'i18n.gettext' PropType is defined but prop is never used react/no-unused-prop-types
This is incorrect because the i18n
property is destructured into a new constant and then the gettext()
function is called. If I edit the code so that it doesn't use destructuring then the error goes away, revealing the bug.
Here is a small app that reproduces it: eslint-scratch.zip. Run:
npm install
npm run eslint
This is similar to #782 but they seem different.