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

Add support for propTypes wrapped in a function #1253

Merged
merged 1 commit into from Jun 16, 2017

Conversation

dustinsoftware
Copy link
Contributor

PropTypes would previously get ignored if wrapped in forbidExtraProps.

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!

However, this behavior should be behind an option (array of strings), and that option should include an explicit identifier name for that function - ie, this should not be considered unless forbidExtraProps is in the eslint config.

@dustinsoftware
Copy link
Contributor Author

Is this what you had in mind?

@@ -44,6 +44,9 @@ module.exports = {
},
skipShapeProps: {
type: 'boolean'
},
extraPropsFunc: {
Copy link
Member

Choose a reason for hiding this comment

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

i think this would be better as an array of unique strings - that way multiples could be provided.

Let's also rename it to "propWrapperFunctions"

@dustinsoftware
Copy link
Contributor Author

Ok, I think it's ready for another pass :)

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.

LGTM pending an update to the docs :-)

type: 'string'
propWrapperFunctions: {
type: 'array',
items: {
Copy link
Member

Choose a reason for hiding this comment

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

please add uniqueItems: true so that jsonschema enforces uniqueness

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.

LGTM!

It'd be nice to rebase this down to a single commit.

@dustinsoftware
Copy link
Contributor Author

👍 rebased. Thanks for the quick feedback.

case 'CallExpression':
if (
configuration.propWrapperFunctions &&
configuration.propWrapperFunctions.indexOf(propTypes.callee.name) !== -1 &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be worth converting the propWrapperFunctions to a structure with constant time lookup, like a Set, to keep this path fast.

case 'CallExpression':
if (
configuration.propWrapperFunctions &&
configuration.propWrapperFunctions.indexOf(propTypes.callee.name) !== -1 &&
Copy link
Member

Choose a reason for hiding this comment

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

that's a really great point. this should definitely be converted to a Set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, updated

@dustinsoftware dustinsoftware force-pushed the forbidExtraProps branch 2 times, most recently from 1520791 to 5d05311 Compare June 16, 2017 03:05
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.

Almost there :-)

@@ -56,6 +63,9 @@ module.exports = {
var configuration = Object.assign({}, defaults, context.options[0] || {});
var skipShapeProps = configuration.skipShapeProps;
var customValidators = configuration.customValidators || [];
var propWrapperFunctions = configuration.propWrapperFunctions ?
new Set(configuration.propWrapperFunctions) : new Set();
Copy link
Member

Choose a reason for hiding this comment

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

var propWrapperFunctions = new Set(configuration.propWrapperFunctions || []);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dargh, thanks...should have caught that one

PropTypes would previously get ignored if wrapped in forbidExtraProps.
@ljharb ljharb merged commit c568d49 into jsx-eslint:master Jun 16, 2017
@ljharb
Copy link
Member

ljharb commented Jun 16, 2017

@dustinsoftware are there other rules that could benefit from this information?

If so, maybe we should move it to "settings", and read from it in multiple rules?

@mqklin
Copy link

mqklin commented Jun 22, 2017

Has it been published?

@ljharb
Copy link
Member

ljharb commented Jun 22, 2017

Nope, not yet.

Copy link
Collaborator

@EvHaus EvHaus left a comment

Choose a reason for hiding this comment

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

LGTM

@mqklin
Copy link

mqklin commented Sep 28, 2017

@ljharb @dustinsoftware
still, doesn't work for me :(
repro: https://github.com/mqklin/eslint-proptypes-bug
image

@ljharb
Copy link
Member

ljharb commented Sep 28, 2017

@mqklin because you haven't explicitly defined it as a propWrapperFunction in your eslintrc.

Please file a new issue if you still have questions instead of commenting on a merged PR.

@mqklin
Copy link

mqklin commented Sep 28, 2017

@ljharb thank you very much! I missed this.

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

Successfully merging this pull request may close these issues.

None yet

5 participants