unicorn/consistent-empty-array-spread

Require both branches of a spread ternary in an array to have the same type

has suggestions

Spreading [] and spreading "" both add nothing to an array, so either works as the "nothing" branch of ...(condition ? items : fallback). But when one branch is an array and the other is a string, the reader needs to stop and work out that the mismatch is harmless.

The rule reports an array followed by "", and a string followed by []. It only looks at the fallback after the :.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/consistent-empty-array-spread" = "error" # or "warn"

Examples#

example.js1 problem
const args = ["build", ...(watch ? ["--watch", "--hot"] : "")];
example.js1 problem
const letters = ["a", ...(more ? "bc" : [])];
example.jsNo problems
const args = ["build", ...(watch ? ["--watch", "--hot"] : [])];

const letters = ["a", ...(more ? "bc" : "")];