Skip to content

unicorn/consistent-empty-array-spread Pedantic ​

💡 A suggestion is available for this rule.

What it does ​

When spreading a ternary in an array, we can use both [] and '' as fallbacks, but it's better to have consistent types in both branches.

Examples ​

Examples of incorrect code for this rule:

javascript
const array = [a, ...(foo ? [b, c] : "")];

const array = [a, ...(foo ? "bc" : [])];

Examples of correct code for this rule:

javascript
const array = [a, ...(foo ? [b, c] : [])];

const array = [a, ...(foo ? "bc" : "")];

References ​

Released under the MIT License.