Eslint-plugin-react: add autofix to sort-default-props

Created on 30 Nov 2018  路  8Comments  路  Source: yannickcr/eslint-plugin-react

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

enhancement help wanted

All 8 comments

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鈥檙e forced to manually address.

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

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 )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

otakustay picture otakustay  路  3Comments

budarin picture budarin  路  3Comments

gpeal picture gpeal  路  3Comments

mericsson picture mericsson  路  3Comments

inian picture inian  路  3Comments