-
-
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
no-useless-spread
it is not safe to remove spread in [...foo.concat(bar)]
#2480
Comments
[...foo.concat(bar)]
[...foo.concat(bar)]
Sparse arrays are an anti-pattern, so we're not going to change the auto-fix, but we should document the issue with sparse arrays, so people can choose to turn off the rule if they want to use sparse arrays. |
So, one way to initialize a non-sparse array is Interestingly, eslint's docs list Linters are here to help us write better code, but if you only accept good code to lint in the first place, I feel like that's missing the point of why people use a linter. If the opinion of the linter is |
You have a good point here, but I think a lot of unicorn rules build on each other. For example - [...new Array(10)]
+ [...Array.from({length: 10})] Then - [...Array.from({length: 10})]
+ Array.from({length: 10})
For your code, this is already being auto-fixed correctly by - [...new Array(10)]
+ Array.from({length: 10}) I can see the same happening for OP's code: - const foo = new Array(5);
- const bar = new Array(5);
+ const foo = Array.from({length: 5});
+ const bar = Array.from({length: 5});
- const cat = [...foo.concat(bar)];
+ const cat = foo.concat(bar); With further advice on the concat, not autofixed:
The result is the same, In short, the advice to "turn off the rule if they want to use sparse arrays" seems valid here. |
[...foo.concat(bar)]
[...foo.concat(bar)]
[...foo.concat(bar)]
[...foo.concat(bar)]
If this is a common pattern, it could be detected and autofixed to For a generic If you think about it, even eslint makes a lot of assumptions on code safety, for example it assumes you don't rewrite |
[...foo.concat(bar)]
no-useless-spread
it is not safe to remove spread in [...foo.concat(bar)]
no-useless-spread
it is not safe to remove spread in [...foo.concat(bar)]
prefer-dom-node-append
: Property 'append' does not exist on type 'ChildNode'.
prefer-dom-node-append
: Property 'append' does not exist on type 'ChildNode'.prefer-dom-node-append
: Property 'append' does not exist on type 'ChildNode'.
prefer-dom-node-append
: Property 'append' does not exist on type 'ChildNode'.prefer-dom-node-append
Property 'append' does not exist on type 'ChildNode'.
prefer-dom-node-append
Property 'append' does not exist on type 'ChildNode'.no-useless-spread
it is not safe to remove spread in [...foo.concat(bar)]
eslint-plugin-unicorn/test/no-useless-spread.mjs
Line 259 in 2b469be
Note
The concat() method preserves empty slots if any of the source arrays is sparse.
via MDN
The text was updated successfully, but these errors were encountered: