git-validator icon indicating copy to clipboard operation
git-validator copied to clipboard

feat(eslint-plugin): `consistent-object-array-spread`

Open zanminkian opened this issue 9 months ago • 1 comments

Array

ok

let name: string = '' ;

if (Math.random() > 0.5) {
  name = "foo"
}

const names = ["bar", ...(name && [name])]

fail

let name: string | undefined = undefined;

if (Math.random() > 0.5) {
  name = "foo"
}

const names = ["bar", ...(name && [name])]

ok

let name: string | undefined = undefined;

if (Math.random() > 0.5) {
  name = "foo"
}

const names = ["bar", ...(name ? [name] : [])]

Object

ok

let name: string | undefined = undefined;

if (Math.random() > 0.5) {
  name = "foo"
}

const student = {age: 12, ...(name&&{name})}

fail

let name: string | undefined = undefined;

if (Math.random() > 0.5) {
  name = "foo"
}

const student = {age: 12, ...(name ? {name} : {})}

zanminkian avatar May 20 '24 07:05 zanminkian