Skip to content

linter: no-useless-spread auto-fix is unsafe #5405

@eventualbuddha

Description

@eventualbuddha

As I commented here, I believe any auto-fix for no-useless-spread is potentially invalid. I provided a specific example in that comment, but in general I don't believe it's possible to statically determine whether iterating over the original iterable vs. a cloned array of the original iterable will yield different results. Here's a fairly trivial example that results in very different results:

const set = new Set([1, 2, 3]);

console.log('before:', set);

for (const element of [...set]) {
  console.log('element:', element);
  set.add(element * 2);
}

console.log('after:', set);

I don't believe auto-fixes should be made unless the lint rule can, with very high confidence, ensure that the semantics are unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linterArea - LinterC-bugCategory - Buggood first issueExperience Level - Good for newcomers

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions