Skip to content
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

New Rule Proposal: enforce return in render() method #482

Closed
silvenon opened this issue Mar 3, 2016 · 5 comments
Closed

New Rule Proposal: enforce return in render() method #482

silvenon opened this issue Mar 3, 2016 · 5 comments
Labels

Comments

@silvenon
Copy link
Contributor

silvenon commented Mar 3, 2016

It sometimes happens to me that I forget to return JSX content in the render method. This rule would warn if the return statement is missing.

@bsbeeks
Copy link

bsbeeks commented Mar 3, 2016

I run into this use case as well. It's fairly easy to catch with the React errors in the browser, but having a rule to help catch it before hand would be great. @yannickcr I can put together a PR for this if it's a rule we want to add.

Proposed Rule Name: require-render-return

@ljharb
Copy link
Member

ljharb commented Mar 3, 2016

What about returning null? What about returning the contents of a function call (which may or may not contain jsx)?

If this is just ensuring that a render method returns something, that's fine, but I'm skeptical about the value it will add.

@bsbeeks
Copy link

bsbeeks commented Mar 3, 2016

In my mind the rule would just check for a return statement in the render method. It wouldn't care about what it's returning. The value add would probably depend on the project and the component. I'm not sure how to measure that value, but I know it'd be useful for our projects at MX (especially for newbie devs)

@yannickcr
Copy link
Member

If this is just ensuring that a render method returns something, that's fine, but I'm skeptical about the value it will add.

Same for me, but if you send a PR for this @bsbeeks I don't really see reasons to refuse it.

@silvenon
Copy link
Contributor Author

silvenon commented Mar 4, 2016

You can always bypass certain rules in some way, you can do const { props } = this and now using props.foo won't check if foo is defined in propTypes.

If a component returns an invalid value, there's not much the plugin can do about it. These concerns are clearly separated. The rule would be just a faster way to see that you forgot to return the JSX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants