Skip to content

Bug: prefer-spread shouldn't encourage iterating over strings #2521

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

prefer-spread reports on String#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 of String#split('') from prefer-spread?

const text = 'hello 👋';

text.split(''); // "fixed" to [...text]

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 then unicorn/prefer-spread reports on String#split(''). You can't win!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions