New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-unused-prop-types errors when declaring an empty function as a default component prop #1581
Comments
Also experiencing this issue |
Shouldn't that be:
? I came here because I experienced the issue, and noticed that I misspelled |
Either way, the OP's code as-typed shouldn't crash. |
I don't understand, what's the full code? I can't reproduce the error, this test case passes: function MyComponent(props) {
return <div>{props.foo()}</div>;
}
MyComponent.defaultProps = {
foo: (() => {}),
} |
@silvenon maybe try with a React Component rather than a function |
@asafda so it only breaks for you on a class-based component? (a function is a React Component too) |
The following test case works as well: class MyComponent extends Component {
render() {
return <div>{this.props.foo()}</div>
}
}
MyComponent.defaultProps = {
foo: (() => {})
}; (Specifying Maybe your lint error was caused by a more specific case? |
I can't reproduce it anymore. I guess it was my mistake as @asbjornh noted. |
Yes, I still suffer from the issue, but looks like it's regarding more about #1542. How can I reproduce:
With v7.4.0 everything is ok |
@AlexMarvelo any chance you could help narrow that down to which file/code is causing the error? One trick is to temporarily edit |
@ljharb This is reproducible in https://github.com/react-bootstrap/react-bootstrap too - occuring in https://github.com/react-bootstrap/react-bootstrap/blob/master/test/utils/bootstrapUtilsSpec.js This is the output with /Users/kevinzwhuang/oss/react-bootstrap/src/ButtonGroup.js
/Users/kevinzwhuang/oss/react-bootstrap/src/MenuItem.js
/Users/kevinzwhuang/oss/react-bootstrap/src/Nav.js
/Users/kevinzwhuang/oss/react-bootstrap/src/Navbar.js
/Users/kevinzwhuang/oss/react-bootstrap/src/TabContainer.js
/Users/kevinzwhuang/oss/react-bootstrap/test/FormControlStaticSpec.js
/Users/kevinzwhuang/oss/react-bootstrap/test/FormGroupSpec.js
/Users/kevinzwhuang/oss/react-bootstrap/test/OverlayTriggerSpec.js
/Users/kevinzwhuang/oss/react-bootstrap/test/utils/bootstrapUtilsSpec.js
Cannot read property 'properties' of undefined
TypeError: Cannot read property 'properties' of undefined
at markPropTypesAsUsed (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:657:38)
at iterateProperties (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:826:15)
at iterateProperties (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:361:11)
at markPropTypesAsDeclared (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:811:11)
at markPropTypesAsDeclared (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:839:13)
at MemberExpression (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint-plugin-react/lib/rules/no-unused-prop-types.js:1028:13)
at listeners.(anonymous function).forEach.listener (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint/lib/util/safe-emitter.js:47:58)
at Array.forEach (native)
at Object.emit (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint/lib/util/safe-emitter.js:47:38)
at NodeEventGenerator.applySelector (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint/lib/util/node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (/Users/kevinzwhuang/oss/react-bootstrap/node_modules/eslint/lib/util/node-event-generator.js:280:22)
(node:58141) DeprecationWarning: [eslint] The 'ecmaFeatures' config file property is deprecated, and has no effect. (found in /Users/kevinzwhuang/oss/react-bootstrap/.eslintrc) I dug a little deeper and reverted #1507 locally, and it looks like #1507 is causing this crash. Not exactly sure why yet, still investigating |
Can you share the contents of |
I agree @ljharb, I opened a PR (#1600) to hopefully resolve this without having to revert. Re: contents of it('should not override other propTypes', () => {
const propTypes = { other() {} };
const Component = () => null;
Component.propTypes = propTypes;
bsStyles(['minimal', 'boss', 'plaid'])(Component);
expect(Component.propTypes).to.exist;
expect(Component.propTypes.other).to.exist;
}); Where |
ah, perhaps the concise method? If you change |
@ljharb Nope, same crash. the test I wrote here uses an arrow function instead (https://github.com/yannickcr/eslint-plugin-react/pull/1600/files#diff-9dbe8e4f339ea9d6faa56b31c38e71bbR2451)
|
@ljharb I found an old file, where |
ESlint version 7.5.1
When adding an empty function as a default prop ESLint exits with the following error:
The default prop is declared as follows:
The text was updated successfully, but these errors were encountered: