Skip to content

Rule proposal: consistent-empty-array-spread #2074

Closed
@fisker

Description

@fisker

Description

When spreading a ternary in array, we can use both

[
	element1,
	...(a ? [b, c] : []),
]

and

[
	element1,
	...(a ? [b, c] : ''),
]

but it's bad to have different style in one project, should enforce consistent style.

Personally, I slightly prefer to use empty array when the consequent is array, but empty string should be cheaper. I hope this rule default to enforce use the same type for "consequent" and "alternate".

Fail

[
	element1,
	...(a ? [b, c] : ''), // use `[]` since "consequent" is array
]
[
	element1,
	...(a ? 'bc' : []), // should use `""` since "consequent" is string
]

Pass

[
	element1,
	...(a ? [b, c] : []), // use `[]` since "consequent" is array
]
[
	element1,
	...(a ? 'bc' : ''), // should use `""` since "consequent" is string
]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions