eslint-plugin-react: It must be possible for ES6 defaultProps be equal to function execution
In the class below:
class TestComponent extends React.Component {
static defaultProps = function () {
const date = new Date();
return {
date
};
}();
}
the defaultProps are equal to a anonymous function return value.
In this case, the eslint-plugin-react doesn’t run, and throws the following error:
TypeError: Cannot read property 'split' of undefined at Object.isPropWrapperFunction (~/project/node_modules/eslint-plugin-react/lib/util/propWrapper.js:12:26) at resolveNodeValue (~/project/node_modules/eslint-plugin-react/lib/util/defaultProps.js:30:23) at Object.ClassProperty (~/project/node_modules/eslint-plugin-react/lib/util/defaultProps.js:222:26) at updatedRuleInstructions.(anonymous function) (~/project/node_modules/eslint-plugin-react/lib/util/Components.js:752:46) at listeners.(anonymous function).forEach.listener (~/project/node_modules/eslint/lib/util/safe-emitter.js:45:58)
I’m using the following versions: “eslint”: “5.10.0” “eslint-plugin-react”: “7.11.1”.
If in the same class I put the defaultProps equal do an object it runs as expected.
Thanks
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (12 by maintainers)
Perfect, I’m able to repro.
@ljharb yeah that’s what I meant there; just thought you might know why that could be unrealistic. I’ll look around their issue tracker. 👍
File with error (i think):
in another file
another file
The OP’s test code doesn’t crash on master.
@jethrolarson I understand. if you edit
lib/rules/forbid-prop-types.jsline 128 toconsole.log(context.getFilename())(i think), it should print out the file at least?