-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Warn if using ES6 class but not directly extending React.Component #1048
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
Comments
How would you propose detecting a component that extends something else? The presence of a "render" method isn't sufficient - Backbone views have a render method, for example - and some subclasses only override lifecycle methods, or only override non lifecycle methods. The current way this is handled is that if a component extends another component, it's ignored - precisely because there's no way to detect them. A new generic rule that prohibited all forms of |
I'm not very familiar with what AST provides, but I assumed that there's be an object name lookup and then another lookup for it's parent that would be |
Your assumption is incorrect - AST is only based on what code is typed into the file. It's utterly impossible to find "the parent" because that might be in another file, or that might be the result of random evaluation. There's no way to know that Your desired rule doesn't target any of these cases. This is the type of thing that just needs to be solved with code review, not with a linter. |
I like the idea of an annotation comment. The plugin could check for |
Note that this plugin already supports an optional annotation comment, but it must not require it, or else the linter rules would miss out on a lot of places it needs to be targeting. |
Is there documentation for this optional annotation comment? |
I believe it's undocumented atm, and uses jsdoc syntax. |
In react, inheriting from something that's not If you do it anyways, you can stick |
Uh oh!
There was an error while loading. Please reload this page.
Now that React 16.x is taking out
createClass
, is there currently a way to warn if not directly extendingReact.(Pure)?Component
. That was always my issue with ES6 classes (Button inherits Tooltip, Tooltip inherits onHoverComponent, etc.) and have been holding off on them. I'm seeingisExplicitComponent
in the utils module which I believe would do this, if surfaced.Maybe it would be an additional feature to prefer-es6-class rule:
'react/prefer-es6-class': [1, 'explicit'],
Anyone else think this is a good idea in order to promote use of higher order components for composition over classical inheritance? This would be in line with @gaearon 's How to Use Classes and Sleep at Night
The text was updated successfully, but these errors were encountered: