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

Rule Proposal: Error for using this in stateless function #672

Closed
nickstanish opened this issue Jul 8, 2016 · 4 comments
Closed

Rule Proposal: Error for using this in stateless function #672

nickstanish opened this issue Jul 8, 2016 · 4 comments

Comments

@nickstanish
Copy link

Would be great to catch these errors faster especially when converting classes to stateless functions

@ljharb ljharb added the new rule label Jul 8, 2016
@Jessidhia
Copy link
Contributor

Wouldn't no-invalid-this catch this?

@ljharb
Copy link
Member

ljharb commented Jul 20, 2016

That's a good point - that's a core rule that prevents use of this in a standalone function. It still might be useful to have one specifically for SFCs, though.

@nickstanish
Copy link
Author

That rule allows this if the function looks like a constructor, and the criteria for that is the name is capitalized or is actually a class constructor. Since SFCs begin with capital letter then that rule would allow it.

One possible solution is to add-on to that rule by determining if the function is a SFC.
The criteria for that could be something similar to:

  • returns jsx or React.createElement/cloneElement
  • has 1 function arg
  • sets propTypes/defaultProps

@alexzherdev
Copy link
Contributor

Added in #1509.

@ljharb ljharb closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants