Skip to content

Handle isRequired for boolean-prop-naming #1701

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

Merged
merged 1 commit into from
Feb 23, 2018

Conversation

louisscruz
Copy link
Contributor

The Problem

There was a bug in boolean-prop-naming where the following would trip the rule:

class Something extends React.Component {
  static propTypes = {
    something: PropTypes.bool
  };
  // ...
}

but the following would not:

class Something extends React.Component {
  static propTypes = {
    something: PropTypes.bool.isRequired
  };
  // ...
}

The Solution

I added an extra conditional to getPropKey to handle this scenario.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both of the added tests, can you add a duplicate copy that parses with the default parser instead of babel-eslint?

const name = node.value.property.name;
if (name === 'isRequired') {
return node.value.object.property.name;
}
return node.value.property.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be return name; now?

@louisscruz
Copy link
Contributor Author

@ljharb Absolutely. On it.

@louisscruz
Copy link
Contributor Author

@ljharb Actually, just gave it a shot, and it seems that any test that uses class properties needs that parser. If I remove it, I get A fatal parsing error occurred: Parsing error: Unexpected token = (even for other tests in this file).

@rapheld
Copy link

rapheld commented Feb 23, 2018

Would love to see this get in

@ljharb
Copy link
Member

ljharb commented Feb 23, 2018

@louisscruz indeed; the code examples using class properties would need to be tweaked so as not to use them.

@louisscruz
Copy link
Contributor Author

@ljharb Oh, I see what you're getting at. Will add those.

@louisscruz
Copy link
Contributor Author

@ljharb Added!

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ljharb ljharb added the bug label Feb 23, 2018
@ljharb ljharb merged commit 9b16cab into jsx-eslint:master Feb 23, 2018
@louisscruz
Copy link
Contributor Author

@yannickcr Any chance you could publish this so I can get access to this bug fix by default?

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

Successfully merging this pull request may close these issues.

3 participants