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' : ''),
];