Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 869 Bytes

consistent-empty-array-spread.md

File metadata and controls

42 lines (32 loc) · 869 Bytes

Prefer consistent types when spreading a ternary in an array literal

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

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.

Fail

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

Pass

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