Eslint-plugin-react: `react/destructuring-assignment` should forgive the use of `this.props.hasOwnProperty`

Created on 21 Dec 2018  路  3Comments  路  Source: yannickcr/eslint-plugin-react

Destructuring the props is a good practice because it shows at the top of the function scope which parameters are being used. However, the hasOwnProperty is built-in and destructuring it doesn鈥檛 reveal much

All 3 comments

It definitely shouldn鈥檛, since hasOwnProperty should never ever under any circumstances be called directly on anything. You want Object.prototype.hasOwnProperty.call(obj, key) instead.

That is handled by no-prototype-builtins in eslint core though (although it's not in the recommended preset)

Very true! Hopefully everyone has that rule enabled.

Which, is why I don't think the destructuring-assignment needs any special rules around it.

Separately, there's literally no value in checking if a prop is passed or not - undefined and "absent" should always be treated the same, no exceptions - based on that, I'm going to close this.

Was this page helpful?
0 / 5 - 0 ratings