-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Bug: prefer-spread
shouldn't encourage iterating over strings
#2521
Comments
prefer-spread
shouldn't encourage iterating over strings
I do appreciate that this is a virtually impossible task to be done correctly by default. |
I'll bring in the quote from the linked tc39 document:
This makes sense but the intent of the rule here is to push people to use a better segmenter. I think that in most cases you do want Alternatively, is this the correct solution? - 'hello 🎅🏻'.split('')
+ [...new Intl.Segmenter().segment('hello 🎅🏻')].map(s => s.segment); |
I believe so. I'm not sure if grapheme splitting is ever locale-sensitive but the general form looks fine. |
Yeah 😕 it's not great how there isn't a single good canonical solution. I think we have a collection of "this might not be right" reports, but no single autofix/suggestion to pair them with. |
prefer-spread
reports onString#split('')
, fixing to a typical...
. That matches the design of string iterability as it was originally intended. However, allowing primitives to be iterated over is widely considered a mistake: https://github.com/tc39/how-we-work/blob/main/normative-conventions.md#reject-primitives-in-iterable-taking-positions.Proposal: can
eslint-plugin-unicorn
remove the preference ofString#split('')
fromprefer-spread
?I'm roughly quoting @Josh-Cena from this discussion: https://github.com/typescript-eslint/typescript-eslint/pull/8509/files#r1781707713. Context: in typescript-eslint, we're implementing typescript-eslint/typescript-eslint#748 Rule proposal: prevent array, iterable and function spreads into objects. The rule is set to report on
...string
by default... and thenunicorn/prefer-spread
reports onString#split('')
. You can't win!The text was updated successfully, but these errors were encountered: