We are using a subclass of React.Component to handle exceptions thrown in render().
PropTypes validation doesn't seem to work with anything subclassed.
Looking for a solution I came upon this issue - https://github.com/yannickcr/eslint-plugin-react/issues/632#issuecomment-363256305.
It states that adding JSDoc comment should solve the issue, meanwhile, it is not.
An example to test this behaviour is available here (run npm test):
https://github.com/seavan/eslint-proptypes-subclass-test
Expected output:
two warnings on missing props validation (for class extending React.Component and for class extending SafeComponent which is a subclass of React.Component).
Actual output:
only one warning, for the class extending React.Component.
(For posterity: subclassing React.Component is considered a very bad antipattern, and the community as well as the React team advises against it)
The /** @extends React.Component */ comment needs to go on the subclass - on the thing that is trying to pretend it extends React.Component. In your example code, you have it on SafeComponent but you need it on TestEslint.
@ljharb it doesn't work that way either (updated the repo)
it seems like it always returns here:
I debugged this piece of code and comment is always null for my example.
is sourceCode.getJSDocComment(node); throwing, or returning null?
it's returning null.
It doesn't seem like we have tests for this behavior; we should add them when fixing this.
I think JSDoc needs one more *. Try to use /** @extends React.Component */.
@pauldijou it worked, thank you!
Most helpful comment
I think JSDoc needs one more
*. Try to use/** @extends React.Component */.