Skip to content

add autofix to sort-default-props #2062

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

Open
hornta opened this issue Nov 30, 2018 · 8 comments
Open

add autofix to sort-default-props #2062

hornta opened this issue Nov 30, 2018 · 8 comments

Comments

@hornta
Copy link

hornta commented Nov 30, 2018

Add same sorting behaviour to sort-default-props as to sort-props

@pawelnvk
Copy link

pawelnvk commented Dec 3, 2018

I would love to help with that one. Be patient, it will be my first contribution.

@VincentLanglet
Copy link
Contributor

With foo = { bar: baz }.

{ ...foo, bar } = { bar }

And

{ bar, ...for } = { baz }

A fixer can break the code

@ljharb
Copy link
Member

ljharb commented Feb 27, 2019

@VincentLanglet an incorrect fixer can break any code; a correct fixer for this rule must not move anything across the boundary created by a spread prop.

@VincentLanglet
Copy link
Contributor

@ljharb I agree that a correct fixer for this rule must not move anything across the boundary created by a spread prop.

But then this fixer won't fix something like

{ a, ...foo, bar }

And actually the expected code is

{ a, bar, ...foo }

But

{ a, bar, ...foo } !== { a, ...foo, bar }

That's why I asked for an option to use the sort-default-props without having eslint asking me or my team to break my code.

@ljharb
Copy link
Member

ljharb commented Feb 27, 2019

Right - the proper thing there is for the autofixer to ignore that change, leaving behind an un-auto-fixable error that you’re forced to manually address.

Perhaps I’ve misunderstood tho; you want an option that does not force sorting across spread boundaries, whether autofixed or not?

@alexzherdev
Copy link
Contributor

FWIW the sort-prop-types autofixer does sort within the spread boundaries: https://github.com/yannickcr/eslint-plugin-react/blob/4a72e6a0784f7cc7f16f4574ce7f14de55540a73/tests/lib/rules/sort-prop-types.js#L1007-L1037

@ljharb
Copy link
Member

ljharb commented Feb 28, 2019

In that case, this option requested in #2178 would, when enabled, just make the autofixer go from "partial" to "full".

@webOS101
Copy link
Contributor

Adding a note here to be sure that, when implemented, it moves any associated comments (as per #1940 )

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

No branches or pull requests

6 participants