Skip to content

Rule proposal: no-reduce-spread #1335

@bschlenk

Description

@bschlenk

Using spread inside a reduce call can turn a O(n) algorithm into O(n**2). See https://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern

Fail

const result = items.reduce((acc, item) => ({
  ...acc,
  [item.name]: item.value,
}, {});

Pass

const result = items.reduce((acc, item) => {
  acc[item.name] = item.value;
  return acc;
}, {})

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions