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

Handle spread in jsx-sort-props #42

Merged
merged 1 commit into from
Mar 30, 2015
Merged

Handle spread in jsx-sort-props #42

merged 1 commit into from
Mar 30, 2015

Conversation

zertosh
Copy link
Contributor

@zertosh zertosh commented Mar 30, 2015

No description provided.

@zertosh
Copy link
Contributor Author

zertosh commented Mar 30, 2015

@yannickcr This is causing the plugin to throw

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 93.57% when pulling 08d791d on zertosh:sort-props-spread into 6eac519 on yannickcr:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 93.57% when pulling 08d791d on zertosh:sort-props-spread into 6eac519 on yannickcr:master.

yannickcr added a commit that referenced this pull request Mar 30, 2015
Handle spread in jsx-sort-props
@yannickcr yannickcr merged commit 106990a into jsx-eslint:master Mar 30, 2015
@yannickcr
Copy link
Member

Thanks, I totally forgot to test the spread attribute.

@zertosh
Copy link
Contributor Author

zertosh commented Mar 30, 2015

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?

@yannickcr
Copy link
Member

Good catch, I think resetting the alpha order after a spread attribute is a good way to handle this case.

@zertosh
Copy link
Contributor Author

zertosh commented Mar 31, 2015

See #47

@lucasmotta
Copy link
Contributor

@zertosh @yannickcr I know I'm late to this party, but shouldn't this be an option too?
I'm working on a pull-request related to this rule and I just wanted to ask first why this isn't optional.

For me the spread operator should be at the end, like on this example:
https://goo.gl/z9QEsU

So I would suggest adding a rule like: resetOnSpread and set its default value to true, so it has backwards compatibility.

What do you guys think? :)

@lucasmotta
Copy link
Contributor

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 

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

Successfully merging this pull request may close these issues.

4 participants