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: validate PropTypes aren't typos #213

Closed
jimbolla opened this issue Sep 9, 2015 · 4 comments · Fixed by #1371
Closed

Rule proposal: validate PropTypes aren't typos #213

jimbolla opened this issue Sep 9, 2015 · 4 comments · Fixed by #1371

Comments

@jimbolla
Copy link

jimbolla commented Sep 9, 2015

Rule would check that calls to React.PropTypes.whatever are valid. For instance, I have a bad habit of typing disabled: PropTypes.bools.isRequired instead of disabled: PropTypes.bool.isRequired. I've also done disabled: propTypes.bool.isRequired and disabled: propTypes.bool.isRequired() by accident.

@mik01aj
Copy link

mik01aj commented Nov 19, 2015

+1, I have the same problem.

I also type React.propTypes instead of React.PropTypes, function instead of func, boolean instead of bool and I'm sometimes tempted to type obj instead of object.

@willklein
Copy link

👍 I have done this a lot. The abbreviations are inconsistent.

I was presenting on how to write lint rules at my React user group last night, and we live coded a first pass: willklein/scaling-best-practices@901534b

Needs more test cases and a few conditions. I'll see if I can get this wrapped up in the next week.

@lencioni
Copy link
Collaborator

lencioni commented Feb 8, 2016

@willklein have you made any progress on wrapping up this rule?

@samsch
Copy link
Contributor

samsch commented Oct 17, 2016

Bumping an old issue with a new case:

class A extends React.Component {
  render() {
    return <a href={this.props.href} >{this.props.children}</a>;
  }
}
A.PropTypes = {
  href: React.PropTypes.string.isRequired,
  children: React.PropTypes.node.isRequired,
}

This code will be linted by react/prop-types as missing prop types for href and children. The subtle problem here is that A.PropTypes = ... should be A.propTypes = ....

Could this rule find and warn/error on a case where prop types are being set in a component property other than propTypes?

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