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

prefer-spread: Fix more .concat cases #1042

Merged
merged 16 commits into from Jan 22, 2021

Conversation

fisker
Copy link
Collaborator

@fisker fisker commented Jan 20, 2021

  1. Support fix empty .concat() call.
  2. If all fixable, auto fix multiple arguments, remove .concat(...).
  3. If some arguments at beginning are fixable, auto-fix code with them and keep .concat(...) with rest arguments.
  4. If FIRST argument is not fixable, suggestion will fix FIRST argument and fixable arguments after first arguments, this can reduce one step when apply suggestions.
  5. .concat(...a) no auto-fix, no suggestions, as we don't know what a is.
  6. Trailing comma will be inserted if last array literal argument or original array literal has it.

Fixes #1041

@fisker fisker marked this pull request as ready for review January 20, 2021 05:48
@@ -531,7 +531,7 @@ Generated by [AVA](https://avajs.dev).
> Output

`␊
1 | [1, 2]␊
1 | [1, 2,]␊
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

Suggested change
1 | [1, 2,]␊
1 | [1, , 2]␊

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No,

> [1,].concat(2)
[ 1, 2 ]
> [1, , 2]
[ 1, <1 empty item>, 2 ]

It fixed in this way, because 2 inserted after 1, and the old [1,] has trailing comma, we keep it, so [1, 2,] is correct.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I misunderstood how concat works with holes. I assumed [1,] would create 1 + a hole, but you need [1,,] to get a hole.

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

Successfully merging this pull request may close these issues.

prefer-spread: Support auto fix for more cases
2 participants