Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.01 KB

File metadata and controls

40 lines (30 loc) · 1.01 KB

consistent-empty-array-spread

📝 Prefer consistent types when spreading a ternary in an array literal.

💼🚫 This rule is enabled in the ✅ recommended config. This rule is disabled in the ☑️ unopinionated 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.

Examples

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

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

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

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