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: force boolean props to be auxiliary verb's #970

Closed
alexreardon opened this issue Nov 22, 2016 · 6 comments
Closed

rule proposal: force boolean props to be auxiliary verb's #970

alexreardon opened this issue Nov 22, 2016 · 6 comments
Labels

Comments

@alexreardon
Copy link

Our code base is looking to enforce the use of auxiliary verb's (eg is, was, should and so on) for boolean props

propTypes = {
  // not allowed
  selected: PropTypes.boolean,

  // allowed
  isSelected: PropTypes.boolean 
}

I was going to write a custom babel plugin for this but I thought it might be a general enough case to put in this repo. I would be happy to write the rule and associated tests.

Cheers

@lencioni
Copy link
Collaborator

I'd be happy to help review a PR that adds this. What do you plan to call it?

It would also be nice to have an option to enforce the opposite.

@alexreardon
Copy link
Author

Sounds good!

@ljharb
Copy link
Member

ljharb commented Nov 27, 2016

Before making a PR, we may want to think about the schema a bit.

For example, I can see wanting exceptions - ie, "require auxiliary verbs for boolean props, except for props that have these names", or "forbid auxiliary verbs for boolean props, except for props that have these names". I can also see wanting to include additional PropTypes in this - in other words, if I have a custom propTypes that is in fact a boolean but has additional validation, I might want the same require/forbid behavior.

It's very important to think about how this rule can be extended, even if the initial PR doesn't need to contain all those features.

@alexreardon
Copy link
Author

Good thinking. In its most general sense this rule is suffix conventions for particular prop types - built in or custom. With the suffix being a limited set of words. In the case of auxiliary verbs it would be 'is, can, should...' and so on.

@ljharb
Copy link
Member

ljharb commented Nov 27, 2016

What schema do you have in mind for allowing the user to specify the propTypes? What about to exempt specific prop names from the rule?

@alexzherdev
Copy link
Contributor

I think this has been achieved in boolean-prop-naming via #1264.

@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
Labels
Development

No branches or pull requests

4 participants