-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Handle spread in jsx-sort-props #42
Conversation
@yannickcr This is causing the plugin to throw |
1 similar comment
Handle spread in jsx-sort-props
Thanks, I totally forgot to test the spread attribute. |
I was thinking about this a little more and there is another subtly that comes with the spread attribute. The spread attribute can be in any position, and that affects the ultimate value of the props passed. So does it make sense to enforce alpha order for all the attributes or to reset it after a spread? E.g.: // this would warn but it shouldn't because I might want my
// "onClick" to override the one in "this.props" - but not
// the "onLoad".
<MyComponent
className="cls"
onLoad={this.onLoad}
{...this.props}
onClick={this.onClick} /> What do you think? |
Good catch, I think resetting the alpha order after a spread attribute is a good way to handle this case. |
See #47 |
@zertosh @yannickcr I know I'm late to this party, but shouldn't this be an option too? For me the spread operator should be at the end, like on this example: So I would suggest adding a rule like: What do you guys think? :) |
And btw, the feature I'm working on is to add an option for shorthand properties at the beginning, like this: <Component x z a="a" b="b" /> // valid
<Component z x a="a" b="b" /> // invalid, should be in alphabetical order
<Component x z b="b" a="a" /> // invalid, should be in alphabetical order
<Component a="a" b="b" x z /> // invalid, shorthand props should be at the start |
No description provided.