Skip to content

'prefer-spread-syntax' rule breaks object properties #79

@alexovn

Description

@alexovn

There're some corner cases like handling Object.assign({}, ...) with array of objects.

Let's look at some examples:

'prefer-spread-syntax' turned Off

const arr = [
  { a: 1 },
  { b: 2 },
  { c: 3 }
]

const obj = Object.assign({}, ...arr)

// { a: 1, b: 2, c: 3 }
// This works right

'prefer-spread-syntax' turned On with eslint . --fix script:

const arr = [
  { a: 1 },
  { b: 2 },
  { c: 3 }
]

const obj = { ......arr } // error (alert) - three more dots for spread

// After dots fix
// { 0: { a: 1 }, 1: { b: 1 }, 2: { c: 1 } }

// Wrong properties in the final object, because Object spread ({ ...obj }) only spreads properties of a single object, not array of objects

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions