Open hornta opened 5 years ago
I would love to help with that one. Be patient, it will be my first contribution.
With foo = { bar: baz }
.
{ ...foo, bar } = { bar }
And
{ bar, ...for } = { baz }
A fixer can break the code
@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.
@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.
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?
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
In that case, this option requested in #2178 would, when enabled, just make the autofixer go from "partial" to "full".
Adding a note here to be sure that, when implemented, it moves any associated comments (as per #1940 )
Add same sorting behaviour to sort-default-props as to sort-props