-
-
Notifications
You must be signed in to change notification settings - Fork 367
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-array-flat
awkward autofix on .concat().concat()
#2470
Comments
prefer-array-flat
overzealous with concat case
prefer-array-flat
overzealous with concat caseprefer-array-flat
awkward autofix on .concat().concat()
I wouldn't classify this as a bug. Garbage in garbage out. The code should be rewritten as |
Can we make the autofix rewrite the code like that? As it stands the autofix seems to make the code worse. |
I think that's already the case thanks to https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-spread.md I don’t think The only reason to have it is because |
It definitely should be in |
Right, but that doesn't mean that it's the best way. The example on that SO page is actually already caught by - [].concat(["$6"], ["$12"], ["$25"], ["$25"], ["$18"], ["$22"], ["$10"]);
+ ["$6", "$12", "$25", "$25", "$18", "$22", "$10"]; The first example uses The problem here is specifically with the plain usage as shown by OP, with again both rules applying to it, and this is what XO currently spits out with - const a = [].concat([1]).concat([2])
+ const a = [...[[1]].flat(), 2] Here's the output after - const a = [].concat([1]).concat([2])
+ const a = [1, 2]
For |
Some people seem to like building up an
Array
, by starting with an empty list and callingconcat()
with extra items.A trivial minimal reproduction would look like this:
When you apply the autofix, it comes out like this, which is clearly nonsense.
It seems the intent of the rule is to stop me using some arcane technique to flatten arrays, but the developers intent here is just to build up a flat list of entries rather than to flatten an
Array
The text was updated successfully, but these errors were encountered: